升级指南
分步指南,升级您的网站至 Reflexjs 2.0。
本指南正在进行中。如果您在升级网站时遇到任何问题,请在 GitHub 上创建问题。我们会提供帮助。
变更日志
新增内容
- Reflexjs 已升级以适用于 React 17.0.0。这意味着我们现在可以完全支持 新的 JSX 变换。
- 我们还升级到了 Theme UI 0.6.0。这引入了一些重大更改(见下文)。
- 变体现在可调用。
theme.tsconst theme = {button: {primary: {bg: "primary",},outline: (theme, styles) => {color: styles?.bg // This returns "primary" with button.primary.outline.},},}<button variant="button.primary.outline" />
重大更改
- TypeScript:React 组件现在必须扩展
React.HTMLAttributes<T>以用于样式属性。
- interface ButtonLinkProps {+ interface ButtonLinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {children?: React.ReactNode}export function ButtonLink({ children, ...props }) {return (<a variant="button.link" {...props}>{children}</a>)}
- 全局样式(
styles.global)已替换为useRootStyles。
theme.tsconst theme = {useRootStyles: true,styles: {// Applies to <html />.root: {m: 0,p: 0,"*": {boxSizing: "border-box",},},},}
useRootStyles: true 将 styles.root 应用到 html。
useRootStyles: false 将 styles.root 应用到 body。
弃用
- 例如
Grid、Flex、Flexbox和Container之类的组件现已弃用。 reflexjs/babel已弃用,并替换为@babel/preset-react。
升级
要将您的网站升级至 Reflexjs
- 更新
react、react-dom和reflexjs。
yarn add react react-dom reflexjs
- 更新
.babelrc。
如果您正在使用Next.js,您的 .babelrc 文件应如下所示
{"presets": [["next/babel",{"preset-react": {"runtime": "automatic","importSource": "reflexjs"}}]]}
- 编辑您的主题,并将
styles.global下的样式移到styles.root下,并设置useRootStyles: true。如果您在 html 下有样式,请直接移到root下。
theme.tsconst theme = {useRootStyles: true,styles: {// Applies to <html />.root: {m: 0,p: 0,"*": {boxSizing: "border-box",},body: {},},},}