|
| 1 | +import React from "react"; |
| 2 | +import Helmet from "react-helmet"; |
| 3 | + |
| 4 | +import { Heading1, Heading2, Text, Link, CodeBlock, Code } from "../docs-components"; |
| 5 | + |
| 6 | +class UpgradeGuide extends React.Component { |
| 7 | + render() { |
| 8 | + return ( |
| 9 | + <div> |
| 10 | + <Helmet title="Upgrade guide – Cosmos" /> |
| 11 | + <Heading1>Upgrading to 0.35.0</Heading1> |
| 12 | + <Text> |
| 13 | + v0.35.0 of Cosmos includes a few breaking changes. These changes are a result of updating styled-components to |
| 14 | + v5 from v3.5, as well as opening up support for SSR (Server Side Rendering). Below is a list of the most |
| 15 | + common required changes to make when upgrading from v0.3X.X. More can be read in styled-component's upgrade |
| 16 | + guide. |
| 17 | + </Text> |
| 18 | + <Text> |
| 19 | + <strong> |
| 20 | + It is recommended you pin your cosmos version, if you have not done so already, until we reach v1.0.0. |
| 21 | + </strong> |
| 22 | + </Text> |
| 23 | + <div> |
| 24 | + <Heading2> |
| 25 | + Global Styles <Code>CssBaseline</Code> |
| 26 | + </Heading2> |
| 27 | + <Text> |
| 28 | + The global styles are no longer added to the head of the document on component import doing this is a side |
| 29 | + effect, and prevented us from supporting SSR. styled-components introduced a helper,{" "} |
| 30 | + <Link href="https://styled-components.com/docs/api#helpers" target="_blank" rel="noreferrer noopener"> |
| 31 | + createGlobalStyle |
| 32 | + </Link> |
| 33 | + , that we are now making use of. To include the global styles you now only need to import and render this |
| 34 | + new CssBaseline component once at the root of your app. |
| 35 | + </Text> |
| 36 | + <CodeBlock language="tsx"> |
| 37 | + {` |
| 38 | +import { CssBaseline } from '@auth0/cosmos'; |
| 39 | +
|
| 40 | +const App = () => ( |
| 41 | + <> |
| 42 | + <CssBaseline /> |
| 43 | + { // ...the rest of your app } |
| 44 | + </> |
| 45 | +); |
| 46 | + `} |
| 47 | + </CodeBlock> |
| 48 | + <Text> |
| 49 | + If you do not want to include CSS resets you can simply include the <Code>includeGlobals</Code> prop to the |
| 50 | + component with a value of false. This replaces the environment variable in previous versions. |
| 51 | + </Text> |
| 52 | + |
| 53 | + <CodeBlock language="tsx"> |
| 54 | + {` |
| 55 | +<CssBaseline includeGlobals={false} /> |
| 56 | + `} |
| 57 | + </CodeBlock> |
| 58 | + </div> |
| 59 | + |
| 60 | + <div> |
| 61 | + <Heading2>innerRef → ref</Heading2> |
| 62 | + <Text> |
| 63 | + styled-components v5 now uses the React utility <Code>forwardRef</Code>. This means that{" "} |
| 64 | + <Code>innerRef</Code> is no longer needed and has been deprecated. For any component that is a result of{" "} |
| 65 | + <Code>styled</Code> if you are using <Code>innerRef</Code> this needs to be switched to use <Code>ref</Code> |
| 66 | + . |
| 67 | + </Text> |
| 68 | + <CodeBlock language="tsx"> |
| 69 | + {` |
| 70 | +const Root = styled.div\`\`; |
| 71 | +
|
| 72 | +// before |
| 73 | +const Foo = () => { |
| 74 | + const rootRef = React.useRef<HTMLDivElement>(); |
| 75 | + return <Root innerRef={rootRef} />; |
| 76 | +}; |
| 77 | +
|
| 78 | +// after |
| 79 | +const Foo = () => { |
| 80 | + const rootRef = React.useRef<HTMLDivElement>(); |
| 81 | + return <Root ref={rootRef} />; |
| 82 | +}; |
| 83 | + `} |
| 84 | + </CodeBlock> |
| 85 | + </div> |
| 86 | + |
| 87 | + <div> |
| 88 | + <Heading2>Component.withComponent has been deprecated</Heading2> |
| 89 | + <Text> |
| 90 | + <Code>Component.withComponent</Code> has been deprecated in favor of the new <Code>as</Code> attribute. |
| 91 | + There are a couple ways to use this: |
| 92 | + </Text> |
| 93 | + <CodeBlock language="tsx"> |
| 94 | + {` |
| 95 | +// before |
| 96 | +const Layout = styled.div\`\`; |
| 97 | +const Root = Layout.withComponent('main'); |
| 98 | +
|
| 99 | +// after |
| 100 | +const Root = styled(Layout).attr({ as: 'main' })\`\`; |
| 101 | +// or |
| 102 | +const root = <Layout as="main" />; |
| 103 | + `} |
| 104 | + </CodeBlock> |
| 105 | + </div> |
| 106 | + |
| 107 | + <div> |
| 108 | + <Heading2>Component.extend(…) has been deprecated</Heading2> |
| 109 | + <Text> |
| 110 | + use <Code>styled(Component)`...`</Code> instead. |
| 111 | + </Text> |
| 112 | + <CodeBlock language="tsx"> |
| 113 | + {` |
| 114 | +// before |
| 115 | +const Layout = styled.div\` |
| 116 | + background-color: blue; |
| 117 | +\`; |
| 118 | +const Root = Layout.extend\` |
| 119 | + color: red; |
| 120 | +\`; |
| 121 | +
|
| 122 | +// after |
| 123 | +const Root = styled(Layout)\` |
| 124 | + color: red; |
| 125 | +\`; |
| 126 | + `} |
| 127 | + </CodeBlock> |
| 128 | + </div> |
| 129 | + </div> |
| 130 | + ); |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +export default UpgradeGuide; |
0 commit comments