The Complete React Native Hooks Course -
// useCallback: memoizes the function itself const handlePress = useCallback(() => console.log('Button pressed', count); , [count]); // Re-create only when count changes // useMemo: memoizes the result of a computation const expensiveValue = useMemo(() => return heavyComputation(data); , [data]);
// Usage in component function UserList() const data, loading, error = useFetch('https://jsonplaceholder.typicode.com/users'); if (loading) return <ActivityIndicator />; if (error) return <Text>Error: error</Text>; return (/* render data */);
const addTodo = (text) => dispatch(addTodoAction(text));
src/ ├── hooks/ │ ├── useFetch.js │ ├── useDebounce.js │ └── useFavorites.js (useReducer based) ├── contexts/ (ThemeContext, FavoritesContext) ├── screens/ (FeedScreen, DetailScreen, FavoritesScreen) └── components/ (NewsCard, SearchBar) ✅ Core hooks: useState , useEffect , useContext ✅ Performance hooks: useCallback , useMemo , React.memo ✅ Refs: useRef for mutable values and DOM access ✅ Advanced: useReducer , custom hooks, navigation hooks ✅ Rules of hooks – no conditional calls ✅ Testing & debugging – DevTools, unit tests ✅ Real-world patterns – infinite scroll, debounced search, cleanup functions ✅ Final project – fully functional React Native app using hooks exclusively The Complete React Native Hooks Course
return data, loading, error ;
export default function AutoFocusInput() const inputRef = useRef(null); const intervalRef = useRef(null); const [timer, setTimer] = useState(0); useEffect(() => inputRef.current?.focus(); // Focus on mount
fetchData();
// 1. Create context const ThemeContext = React.createContext('light'); // 2. Provide value at a top level export default function App() return ( <ThemeContext.Provider value="dark"> <ThemedComponent /> </ThemeContext.Provider> );
if (loading) return <ActivityIndicator size="large" />; return ( <View> <Text>JSON.stringify(data)</Text> </View> );
return ( <View> <TextInput placeholder="Enter your name" value=name onChangeText=setName style= borderWidth: 1, margin: 10, padding: 8 /> <Button title="Submit" onPress=() => setSubmitted(true) /> submitted && <Text>Hello, name!</Text> </View> ); Consume in any child function ThemedComponent() const theme
// 3. Consume in any child function ThemedComponent() const theme = React.useContext(ThemeContext); return <Text style= color: theme === 'dark' ? 'white' : 'black' >Hello</Text>;
useEffect(() => let isMounted = true; // Prevents setting state if component unmounts
import React, useState, useEffect from 'react'; import View, Text, ActivityIndicator from 'react-native'; export default function FetchData() const [data, setData] = useState(null); const [loading, setLoading] = useState(true); let isMounted = true
import React, useState from 'react'; import View, Text, Button, TextInput from 'react-native'; export default function UserInput() const [name, setName] = useState(''); const [submitted, setSubmitted] = useState(false);
"plugins": ["react-hooks"], "rules": "react-hooks/rules-of-hooks": "error", "react-hooks/exhaustive-deps": "warn"