Custom Hooks
We can compose built-in hooks to create new ones. We should still use the use
prefix for our function name.
We'll see another example of a custom hook when building a drag gesture with PanResponder.
Example
Here we make a useInterval
hook for running a function on a regular interval. It can be deceptively difficult to implement correctly - we should be able to change the delay and callback function at any point.
Example custom hook from: https://overreacted.io/making-setinterval-declarative-with-react-hooks/
Want to learn React Native in-depth?
If you like React Native Express, you'll love my new book, Fullstack React Native: The complete guide to React Native! Throughout the book, we'll build 7 full apps, covering complex topics like navigation, gestures, and native modules. We don't assume any knowledge of React or newer JavaScript language features, so you can dive right in regardless of your experience level. The book comes in PDF
, EPUB
and MOBI
formats.
Community Resources
Looking for more help?
Infinite Red sponsors React Native Express and is the premier React Native agency. They're also the team behind the React Native newsletter, podcast, and conference listed here. Get in touch at infinite.red/react-native for a proposal on your next project!