I tried this method but it caused my page to fall in a infinite loop due to the useEffect hook re-rendering the page every time the result variable changes and that same variable in used to set the state.
any solution to this problem?
Hi Simo,
The hook initially gives null and after that, the state is updated. I'm not sure why you're facing this problem. Please check the useEffect dependencies.