Skip to content

Commit 313ccd8

Browse files
committed
Fix RN 0.69 React 18 type errors (FunctionComponent props)
- React 17: interface FunctionComponent<P = {}> { (props: PropsWithChildren<P>, ... - React 18: interface FunctionComponent<P = {}> { (props: P, ... - Doc deprecated prop-types error, later remove - Update linter config @typescript-eslint/no-unnecessary-type-arguments doc comment
1 parent 657e766 commit 313ccd8

File tree

6 files changed

+14
-10
lines changed

6 files changed

+14
-10
lines changed

β€Ž.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ module.exports = {
8585
* - class Atom extends Component<{ children: ReactNode, onPress: () => void }>
8686
* - const Atom = ({ children, onPress }: { children: ReactNode; onPress: () => void }) => <></> // Inferred JSX.Element
8787
* - const Atom: FC<{ onPress: () => void }>
88+
* React 17 PropsWithChildren, now removed for generic P in React 18
8889
*/
8990
'@typescript-eslint/no-unnecessary-type-arguments': 'off',
9091
'@typescript-eslint/no-unused-vars': [

β€Žsrc/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable react-native/no-raw-text, no-console */
22
// https://github.com/Intellicode/eslint-plugin-react-native/issues/271
33

4-
import type { FC } from 'react'
4+
import type { FC, ReactNode } from 'react'
55
import {
66
SafeAreaView,
77
ScrollView,
@@ -29,7 +29,10 @@ if (__DEV__) {
2929
.catch(() => console.error)
3030
}
3131

32-
const Section: FC<{ title: string }> = ({ children, title }) => {
32+
const Section: FC<{ children: ReactNode; title: string }> = ({
33+
children,
34+
title
35+
}) => {
3336
const isDarkMode = useColorScheme() === 'dark'
3437
return (
3538
<View style={styles.sectionContainer}>

β€Žstorybook/stories/Button/index.android.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { FC } from 'react'
1+
import type { FC, ReactNode } from 'react'
22
import { TouchableNativeFeedback } from 'react-native'
33

4-
const Button: FC<{ onPress: () => void }> = ({
4+
const Button: FC<{ children: ReactNode; onPress: () => void }> = ({
55
onPress = () => {
66
// do nothing.
77
},

β€Žstorybook/stories/Button/index.ios.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { FC } from 'react'
1+
import type { FC, ReactNode } from 'react'
22
import { TouchableHighlight } from 'react-native'
33

4-
const Button: FC<{ onPress: () => void }> = ({
4+
const Button: FC<{ children: ReactNode; onPress: () => void }> = ({
55
onPress = () => {
66
// do nothing.
77
},

β€Žstorybook/stories/CenterView/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// eslint-disable-next-line import/no-extraneous-dependencies
22
import PropTypes from 'prop-types'
3-
import type { FC } from 'react'
3+
import type { FC, ReactNode } from 'react'
44
import { View } from 'react-native'
55

66
import style from './style'
77

8-
const CenterView: FC = ({ children }) => {
8+
const CenterView: FC<{ children: ReactNode }> = ({ children }) => {
99
return <View style={style.main}>{children}</View>
1010
}
1111

@@ -14,6 +14,7 @@ CenterView.defaultProps = {
1414
}
1515

1616
CenterView.propTypes = {
17+
// @ts-expect-error Type 'Requireable<ReactNodeLike>' is not assignable to type 'Validator<ReactNode>'
1718
children: PropTypes.node
1819
}
1920

β€Žstorybook/stories/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { action } from '@storybook/addon-actions'
22
import { text, withKnobs } from '@storybook/addon-knobs'
33
import { linkTo } from '@storybook/addon-links'
44
import { storiesOf } from '@storybook/react-native'
5-
import type { FC } from 'react'
65
import { Text } from 'react-native'
76

87
// eslint-disable-next-line import/extensions, import/no-unresolved
@@ -16,7 +15,7 @@ storiesOf('Welcome', module).add('to Storybook', () => (
1615

1716
storiesOf('Button', module)
1817
.addDecorator(withKnobs)
19-
.addDecorator(getStory => <CenterView>{getStory() as FC}</CenterView>)
18+
.addDecorator(getStory => <CenterView>{getStory()}</CenterView>)
2019
.add('with text', () => (
2120
<Button onPress={action('clicked-text')}>
2221
<Text>{text('title', 'Button Title')}</Text>

0 commit comments

Comments
Β (0)