| code SandBox - my favorite |
useState Hook :
- used in functional component
- use at the top
- use to maintain state for example initial value and update value
useEffect Hook:
- show what to decide after render
- works with function
- render will be whenever there are changes in some values or update the contents
- it calls automatically after render
- by default, it automatically calls whenever there are changes even if we use the useEffect on the button. When any change happens that will be called because render will occur
- to solve this we use an array like we specify the only num.
the syntax is like
useEffect(() => {
alert(" i am called ");
}, [num]);
Here is a preview (although messy but it reflects what is actually happening ):
Comments
Post a Comment