React Native Hooks
React Native APIs turned into React Hooks allowing you to access asynchronous APIs directly in your functional components.
Note: You must use React Native >= 0.59.0
Installation with npm
npm install react-native-hooks
Installation with yarn
yarn add react-native-hooks
API
- useAccessibilityInfo
- useAppState
- useBackHandler
- useCameraRoll
- useClipboard
- useDimensions
- useKeyboard
- useInteractionManager
- useDeviceOrientation
- useLayout
useAccessibilityInfo
const isScreenReaderEnabled =
useAppState
AppState will change between one of 'active', 'background', or (iOS) 'inactive' when the app is closed or put into the background.
const currentAppState =
useBackHandler
useCameraRoll
const photos getPhotos saveToCameraRoll = photos <Button title='Get Photos' onPress= >Get Photos</Button>
useClipboard
const data setString = <Text>data</Text> <Button title='Update Clipboard' onPress= >Set Clipboard</Button>
useDimensions
Gets dimensions and sets up a listener that will change the dimensions if the user changes device orientation.
const dimensions = // orconst width height = window// orconst screen = screen
useKeyboard
const keyboard = consoleconsole
useInteractionManager
const interactionReady = console
useDeviceOrientation
const orientation = consoleconsole
useLayout
const onLayout ...layout = console <View onLayout=onLayout style=width: 200 height: 200 marginTop: 30 />