Browse Source
[Beta] Upgrade React Types & Fix resulting type issues (#4694)
* upgrade react types
* fix type errors after upgrade
main
Felix Leupold
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with
22 additions and
19 deletions
-
beta/package.json
-
beta/src/components/Layout/useMediaQuery.tsx
-
beta/src/components/MDX/Sandpack/DownloadButton.tsx
-
beta/src/components/MDX/Sandpack/SandpackRoot.tsx
-
beta/src/pages/_app.tsx
-
beta/src/utils/toCommaSeparatedList.tsx
-
beta/yarn.lock
|
@ -48,8 +48,8 @@ |
|
|
"@types/mdx-js__react": "^1.5.2", |
|
|
"@types/mdx-js__react": "^1.5.2", |
|
|
"@types/node": "^14.6.4", |
|
|
"@types/node": "^14.6.4", |
|
|
"@types/parse-numeric-range": "^0.0.1", |
|
|
"@types/parse-numeric-range": "^0.0.1", |
|
|
"@types/react": "^16.9.46", |
|
|
"@types/react": "^18.0.9", |
|
|
"@types/react-dom": "^16.9.8", |
|
|
"@types/react-dom": "^18.0.5", |
|
|
"@typescript-eslint/eslint-plugin": "2.x", |
|
|
"@typescript-eslint/eslint-plugin": "2.x", |
|
|
"@typescript-eslint/parser": "2.x", |
|
|
"@typescript-eslint/parser": "2.x", |
|
|
"asyncro": "^3.0.0", |
|
|
"asyncro": "^3.0.0", |
|
|
|
@ -7,7 +7,7 @@ import {useState, useCallback, useEffect} from 'react'; |
|
|
const useMediaQuery = (width: number) => { |
|
|
const useMediaQuery = (width: number) => { |
|
|
const [targetReached, setTargetReached] = useState(false); |
|
|
const [targetReached, setTargetReached] = useState(false); |
|
|
|
|
|
|
|
|
const updateTarget = useCallback((e) => { |
|
|
const updateTarget = useCallback((e: MediaQueryListEvent) => { |
|
|
if (e.matches) { |
|
|
if (e.matches) { |
|
|
setTargetReached(true); |
|
|
setTargetReached(true); |
|
|
} else { |
|
|
} else { |
|
|
|
@ -12,6 +12,7 @@ let supportsImportMap: boolean | void; |
|
|
function useSupportsImportMap() { |
|
|
function useSupportsImportMap() { |
|
|
function subscribe() { |
|
|
function subscribe() { |
|
|
// It never updates.
|
|
|
// It never updates.
|
|
|
|
|
|
return () => {}; |
|
|
} |
|
|
} |
|
|
function getCurrentValue() { |
|
|
function getCurrentValue() { |
|
|
if (supportsImportMap === undefined) { |
|
|
if (supportsImportMap === undefined) { |
|
@ -24,7 +25,7 @@ function useSupportsImportMap() { |
|
|
function getServerSnapshot() { |
|
|
function getServerSnapshot() { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
// @ts-ignore
|
|
|
|
|
|
return React.useSyncExternalStore( |
|
|
return React.useSyncExternalStore( |
|
|
subscribe, |
|
|
subscribe, |
|
|
getCurrentValue, |
|
|
getCurrentValue, |
|
|
|
@ -11,7 +11,7 @@ import {createFileMap} from './createFileMap'; |
|
|
import type {SandpackSetup} from '@codesandbox/sandpack-react'; |
|
|
import type {SandpackSetup} from '@codesandbox/sandpack-react'; |
|
|
|
|
|
|
|
|
type SandpackProps = { |
|
|
type SandpackProps = { |
|
|
children: React.ReactChildren; |
|
|
children: React.ReactNode; |
|
|
autorun?: boolean; |
|
|
autorun?: boolean; |
|
|
setup?: SandpackSetup; |
|
|
setup?: SandpackSetup; |
|
|
showDevTools?: boolean; |
|
|
showDevTools?: boolean; |
|
|
|
@ -12,7 +12,9 @@ import '../styles/index.css'; |
|
|
import '../styles/sandpack.css'; |
|
|
import '../styles/sandpack.css'; |
|
|
import '@codesandbox/sandpack-react/dist/index.css'; |
|
|
import '@codesandbox/sandpack-react/dist/index.css'; |
|
|
|
|
|
|
|
|
const EmptyAppShell: React.FC = ({children}) => <>{children}</>; |
|
|
const EmptyAppShell = ({children}: {children: React.ReactNode}) => ( |
|
|
|
|
|
<>{children}</> |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
if (typeof window !== 'undefined') { |
|
|
if (typeof window !== 'undefined') { |
|
|
if (process.env.NODE_ENV === 'production') { |
|
|
if (process.env.NODE_ENV === 'production') { |
|
|
|
@ -4,18 +4,18 @@ |
|
|
|
|
|
|
|
|
import React from 'react'; |
|
|
import React from 'react'; |
|
|
|
|
|
|
|
|
const addString = (list: React.ReactNodeArray, string: string) => |
|
|
const addString = (list: React.ReactNode[], string: string) => |
|
|
list.push(<span key={`${list.length}-${string}`}>{string}</span>); |
|
|
list.push(<span key={`${list.length}-${string}`}>{string}</span>); |
|
|
|
|
|
|
|
|
function toCommaSeparatedList<Item>( |
|
|
function toCommaSeparatedList<Item>( |
|
|
array: Item[], |
|
|
array: Item[], |
|
|
renderCallback: (item: Item, index: number) => void |
|
|
renderCallback: (item: Item, index: number) => React.ReactNode |
|
|
): Array<any> { |
|
|
): React.ReactNode[] { |
|
|
if (array.length <= 1) { |
|
|
if (array.length <= 1) { |
|
|
return array.map(renderCallback); |
|
|
return array.map(renderCallback); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const list: any = []; |
|
|
const list: React.ReactNode[] = []; |
|
|
|
|
|
|
|
|
array.forEach((item, index) => { |
|
|
array.forEach((item, index) => { |
|
|
if (index === array.length - 1) { |
|
|
if (index === array.length - 1) { |
|
|
|
@ -912,12 +912,12 @@ |
|
|
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.4.tgz#fcf7205c25dff795ee79af1e30da2c9790808f11" |
|
|
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.4.tgz#fcf7205c25dff795ee79af1e30da2c9790808f11" |
|
|
integrity sha512-rZ5drC/jWjrArrS8BR6SIr4cWpW09RNTYt9AMZo3Jwwif+iacXAqgVjm0B0Bv/S1jhDXKHqRVNCbACkJ89RAnQ== |
|
|
integrity sha512-rZ5drC/jWjrArrS8BR6SIr4cWpW09RNTYt9AMZo3Jwwif+iacXAqgVjm0B0Bv/S1jhDXKHqRVNCbACkJ89RAnQ== |
|
|
|
|
|
|
|
|
"@types/react-dom@^16.9.8": |
|
|
"@types/react-dom@^18.0.5": |
|
|
version "16.9.14" |
|
|
version "18.0.5" |
|
|
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-16.9.14.tgz#674b8f116645fe5266b40b525777fc6bb8eb3bcd" |
|
|
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.0.5.tgz#330b2d472c22f796e5531446939eacef8378444a" |
|
|
integrity sha512-FIX2AVmPTGP30OUJ+0vadeIFJJ07Mh1m+U0rxfgyW34p3rTlXI+nlenvAxNn4BP36YyI9IJ/+UJ7Wu22N1pI7A== |
|
|
integrity sha512-OWPWTUrY/NIrjsAPkAk1wW9LZeIjSvkXRhclsFO8CZcZGCOg2G0YZy4ft+rOyYxy8B7ui5iZzi9OkDebZ7/QSA== |
|
|
dependencies: |
|
|
dependencies: |
|
|
"@types/react" "^16" |
|
|
"@types/react" "*" |
|
|
|
|
|
|
|
|
"@types/react@*": |
|
|
"@types/react@*": |
|
|
version "17.0.38" |
|
|
version "17.0.38" |
|
@ -928,10 +928,10 @@ |
|
|
"@types/scheduler" "*" |
|
|
"@types/scheduler" "*" |
|
|
csstype "^3.0.2" |
|
|
csstype "^3.0.2" |
|
|
|
|
|
|
|
|
"@types/react@^16", "@types/react@^16.9.46": |
|
|
"@types/react@^18.0.9": |
|
|
version "16.14.21" |
|
|
version "18.0.9" |
|
|
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.14.21.tgz#35199b21a278355ec7a3c40003bd6a334bd4ae4a" |
|
|
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.9.tgz#d6712a38bd6cd83469603e7359511126f122e878" |
|
|
integrity sha512-rY4DzPKK/4aohyWiDRHS2fotN5rhBSK6/rz1X37KzNna9HJyqtaGAbq9fVttrEPWF5ywpfIP1ITL8Xi2QZn6Eg== |
|
|
integrity sha512-9bjbg1hJHUm4De19L1cHiW0Jvx3geel6Qczhjd0qY5VKVE2X5+x77YxAepuCwVh4vrgZJdgEJw48zrhRIeF4Nw== |
|
|
dependencies: |
|
|
dependencies: |
|
|
"@types/prop-types" "*" |
|
|
"@types/prop-types" "*" |
|
|
"@types/scheduler" "*" |
|
|
"@types/scheduler" "*" |
|
|