프로그래밍/React Native
[React Native] TypeScript 빨간맛, 'View' cannot be used as a JSX component.
CaffeLatte
2022. 9. 26. 18:56
react: 17.0.2
react-native: 0.65.1
TS2786: 'View' cannot be used as a JSX component.
Its instance type 'View' is not a valid JSX element.
The types returned by 'render()' are incompatible between these types.
Type 'import("/Users/.../node_modules/@types/react-native/node_modules/@types/react/index").
ReactNode' is not assignable to type 'React.ReactNode'.
Type '{}' is not assignable to type 'ReactNode'.
실행하는데는 전혀 문제가 없지만
빨간맛이 신경쓰인다
구글링해보니,
'Drawer.Navigator' cannot be used as a JSX component with TypeScript · Issue #10507 · react-navigation/react-navigation
Current behavior In the code as follows, I encountered a TypeScript Error message saying 'Drawer.Navigator' cannot be used as a JSX component. import { View, Text } from "react-native&...
github.com
@types/react의 다양한 버전이 문제를 발생시킨다고 한다
해결책은
Yarn
Fast, reliable, and secure dependency management.
classic.yarnpkg.com
package.json에
추가를 하고 yarn install을 해보자
npm 사용자는
package.json | npm Docs
Specifics of npm's package.json handling
docs.npmjs.com
여기를 참조하면 되는듯
이제 해당 코드로 가보면
빨간맛이 사라졌을 것이다
끝.