Created
October 27, 2022 11:44
-
-
Save jessgusclark/2c3e99b9af0606fa452f8ec9e4803d64 to your computer and use it in GitHub Desktop.
React Native Example Component for User Services
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { React, ReactElement, useState } from 'react' | |
import { StyleSheet, View } from 'react-native' | |
import {selectSomeGlobalState} from './somefolder' | |
// Props described as an interface(always use on objects) | |
// type keyword is usually used to describe union types, | |
// navigation types. | |
interface Props { | |
// required props in the beginning | |
children: ReactElement | |
// Optionals always at the end | |
bool?: boolean | |
} | |
// Always use named exports since it makes the debugging easier | |
// and makes you name your components carefully to avoid nameclash | |
export const ExampleComponent = ({ children, bool, ...props }: Props) => { | |
// first global state | |
const globalState = useSelector(selectSomeGlobalState) // or any other state maganager imports | |
// then local state | |
const [state, setState] = useState<object>({}) | |
return ( | |
<View style={styles.someStyle}> | |
{ | |
// Your code here | |
} | |
<View>{children}</View> | |
</View> | |
) | |
} | |
// write styles which belong to a file inside that file | |
const styles = StyleSheet.create({ | |
// use castStyle util for better typing | |
someStyle: { | |
flex: 1, | |
justifyContent: 'center', | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment