// 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 */);
useFocusEffect( useCallback(() => // Reload data when screen comes into focus loadUserData(userId); return () => console.log('Screen unfocused'); , [userId]) ); The Complete React Native Hooks Course
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; // Usage in component function UserList() const data,
export default function AutoFocusInput() const inputRef = useRef(null); const intervalRef = useRef(null); const [timer, setTimer] = useState(0); useEffect(() => inputRef.current?.focus(); // Focus on mount if (loading) return <
"plugins": ["react-hooks"], "rules": "react-hooks/rules-of-hooks": "error", "react-hooks/exhaustive-deps": "warn"
return () => clearInterval(intervalRef.current); , []);
import useSelector, useDispatch from 'react-redux'; function TodoList() const todos = useSelector(state => state.todos.items); const dispatch = useDispatch();