Skip to content

Latest commit

 

History

History
36 lines (27 loc) · 820 Bytes

5. React Hooks.md

File metadata and controls

36 lines (27 loc) · 820 Bytes

📌 React Hooks

  • useState is similiar to an object / variable, allowing us to create dinamic components:

[ VAR, SETTER]

// state variable
const [tasks, setTasks] = useState([]);
  • useEffect is a side effect function ( that's going to be activated after something like the page renderization ):
// This is a side effect (runs after the render)
useEffect(() => {
    async function loadTasks() {
        const res = await getAllTasks();
        console.log(res);
        setTasks(res.data);
    }

    loadTasks();
}, []);
  • useNavigate is the hook that allow navigation / redirect without page refresh:
// Navigator to redirect to the App.js specified route path
const navigate = useNavigate();

const handleClick = () => {
    navigate("/tasks/" + task.title);
};