Learning Outcomes - 02nd April

REACT HOOKS

useState
usage

const [data, setData] =  useState([])

useState is the hook (function) with the default value of the data(state), in this case, an empty array.
useState returns an array of 2 elements:
data is a variable that holds the state of the component
setData is a function used to set the value of data

With useState, you don’t have to manually set the state and find the function. All that functionality is catered for into the simple one-liner.

useEffect
usage

useEffect(() => {
// Update the document title using the browser API
document.title = `You clicked ${count} times`;
});

useEffect is called every time the component renders, it is like the componentDidmount(), componentDidUpdate and componentWillUnmount all combined into one. 

useEffect can be used to handle async actions like fetching data from an API and it re-renders the component once the data has been fetched.

Resource : https://reactjs.org/docs/hooks-effect.html

Previous
Previous

Learning Outcomes - 03 April

Next
Next

Learning Outcomes - 31st March