score:3

Accepted answer

useMemo gets triggered every time the value changes because you add it with [value] as the second parameter. That is why inserting a new value into the input leads to a new computation. useMemo is used to prevent unnecessary calculations, if something else, but not value, changes. But since the only thing that can change is your value, you see the calculation done every time. If the component has more state/prop values, you would see that the computation will be skipped, if these other state/prop values change. Hope this makes it clearer. Happy coding.


Related Query

More Query from same tag