1
2const [a,setA]=useState(0);
3const [b,setB]=useState(0);
4
5const pow=(a)=>{
6 return Math.pow(a,2);
7}
8
9var val= useMemo(()=>{
10 return pow(a); // calling pow function using useMemo hook
11},[a]); // only will be called once a will changed (for "a" we can maintain state)
12
13
14return(
15
16 <input type="text" onChange={(e)=>{setA(e.target.value)}}>
17 <input type="text" onChange={(e)=>{setB(e.target.value)}}>
18
19
20
21 {val} // to access the value from useMemo
22)
23
24
25
26