Using Ref will introduce a new kind of bug into the app.
Let's see this case using usePrevious
that someone commented before:
- prop.minTime: 5 ==> ref.current = 5 | set ref.current
- prop.minTime: 5 ==> ref.current = 5 | new value is equal to ref.current
- prop.minTime: 8 ==> ref.current = 5 | new value is NOT equal to ref.current
- prop.minTime: 5 ==> ref.current = 5 | new value is equal to ref.current
As we can see here, we are not updating the internal ref
because we are using useEffect