The Complete React Native Hooks Course -
const addTodo = (text) => dispatch(addTodoAction(text));
export default function Counter() const [state, dispatch] = useReducer(reducer, initialState); The Complete React Native Hooks Course
useFocusEffect( useCallback(() => // Reload data when screen comes into focus loadUserData(userId); return () => console.log('Screen unfocused'); , [userId]) ); const addTodo = (text) =>
const initialState = count: 0, step: 1 ; function reducer(state, action) switch (action.type) case 'increment': return ...state, count: state.count + state.step ; case 'decrement': return ...state, count: state.count - state.step ; case 'setStep': return ...state, step: action.payload ; default: return state; export default function Counter() const [state
import useNavigation, useRoute, useFocusEffect from '@react-navigation/native'; function ProfileScreen() const navigation = useNavigation(); const route = useRoute(); const userId = route.params;
intervalRef.current = setInterval(() => setTimer(t => t + 1); , 1000);
Goal: Memoize functions and values to prevent unnecessary re-renders.