Skip to main content

升级到 React 18

正在更新软件包

🌐 Updating packages

要使用 React 18 的最新功能,你至少需要 3.0.0 版本的 Remotion。

🌐 To use React 18's newest features, you need at least version 3.0.0 of Remotion.

- "remotion": "2.6.15"
- "@remotion/bundler": "2.6.15"
- "@remotion/cli": "2.6.15"
- "@remotion/renderer": "2.6.15"
+ "remotion": "3.0.0"
+ "@remotion/bundler": "3.0.0"
+ "@remotion/cli": "3.0.0"
+ "@remotion/renderer": "3.0.0"

你需要升级 reactreact-dom

🌐 You need to upgrade both react and react-dom:

- "react": "17.0.1"
- "react-dom": "17.0.1"
+ "react": "18.2.0"
+ "react-dom": "18.2.0"

如果你使用 TypeScript,请同时更新到最新的类型:

🌐 If you use TypeScript, update to the newest types as well:

- "@types/react": "17.0.3"
+ "@types/react": "18.0.0"

之后运行 npm iyarnpnpm i,与你的包管理器相匹配。

🌐 Run npm i, or yarn, or pnpm i afterwards, matching your package manager.

修复 React.FC 类型

🌐 Fixing React.FC types

React.FC 的类型已更改,不再包括 children。如果你遇到类型错误,请更改

🌐 The types for React.FC have changed to no longer include children. If you get a type error, change

const MyComp: React.FC = ({ children }) => <div>{children}</div>;

to:

const MyComp: React.FC<{
  children: React.ReactNode;
}> = ({ children }) => <div>{children}</div>;

createRoot()无需操作

🌐 No action required for createRoot()

如果安装了 React 18,Remotion 将自动使用来自 react-dom/clientcreateRoot(),而不是来自 react-domrender。你无需做任何操作。

🌐 If React 18 is installed, Remotion will automatically use createRoot() from react-dom/client instead of render from react-dom. You don't need to do anything.