ReactNative Typescript
1. react-native typescript
https://reactnative.dev/docs/typescript
-Adding TypeScript to an Existing Project
npm install -D typescript @types/jest @types/react @types/react-native @types/react-test-renderer
make tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"isolatedModules": true,
"jsx": "react-native",
"lib": ["es2017"],
"moduleResolution": "node",
"noEmit": true,
"strict": true,
"target": "esnext"
},
"exclude": [
"node_modules",
"babel.config.js",
"metro.config.js",
"jest.config.js"
]
}
index.js는 절대 건딜지 말것
.js ---> .tsx 로 모두 바꿔줄것
2.styled-component typescript
https://styled-components.com/docs/api#typescript
Web
npm install --save @types/styled-components
React Native
npm install --save @types/styled-components @types/styled-components-react-native
2-1. make styled.d.ts file
import 'styled-components'
declare module 'styled-components' {
export interface DefaultTheme {
mainBgColor: string
textColor: string
accentColor: string
}
}~~~~
mainBgColor, textColor, accentColor은
styled.js에 있는 변수임
사용!
~~const Column = styled.View`
justify-content: center;
align-items: center;
background-color: ${props => props.theme.mainBgColor};
`~~
# 3. react-navigation typescript
https://reactnavigation.org/docs/typescript/
const Movies: React.FC<NativeStackScreenProps<any, 'Movies'>> = ({
navigation,
}) => (
<Header>
<Column>
<Btn onPress={() => navigation.navigate('Stack', { screen: 'three' })}>
<Title>Movies</Title>
</Btn>
</Column>
<Fotter>123123</Fotter>
</Header>
Similarly, you can import StackNavigationProp from @react-navigation/stack, DrawerNavigationProp from @react-navigation/drawer, BottomTabNavigationProp from @react-navigation/bottom-tabs etc.
Author And Source
이 문제에 관하여(ReactNative Typescript), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@jinyinshu/ReactNative-Typescript저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)