Thales Domingues Tip 👇
Finally, ⚛️ React has provided a way to access the latest props and states in effects (useEffect/useLayoutEffect) without causing re-renders.
The useEffectEvent hook will help achieve this.
The hook helps extract non-reactive logic from useEffect webhooks. Non-reactive logic refers to when we don't want to perform any action.
The useEffectEvent hook wraps a callback function and returns an Effect Event function, and whenever it gets called, the function has access to the latest props and state.
So, it won't trigger a re-render, unlike in the case of dependency arrays.
But it's not the replacement of the dependency array, as that is usually required to trigger effects.
You should try it in your workflow as per the use cases.
#react
#javascript
#frontend
#hooks
Insightful