You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Notice how AuthContext only returns JSX using ( ) instead of { }
React Hooks
Special functions
Do cool stuff inside functional components
ex. Use state
useState()
Use state within functional component
const[fruit,setFruit]=useState('orange');// equivalent tovarfruitStateVariable=useState('orange');// Returns a pairvarfruit=fruitStateVariable[0];// First item in a pairvarsetFruit=fruitStateVariable[1];// Second item in a pair
orange is the initial value of fruit
setFruit is basically the setState function for class components
useState returns a pair, an array of 2 items
First item is the current value, and the second is a function that lets us update it
useEffect()
Run code when a component renders/re-renders
By default, runs after all data changes
// only run hook when fruit data changesuseEffect(()=>{
...
},[fruit])
Can pass in an array of data that we want to watch for changes