๐ฅ๐ฒ๐ฎ๐ฐ๐ ๐ญ๐ต: ๐๐๐ฒ() ๐๐ ๐๐๐ฒ๐๐ณ๐ณ๐ฒ๐ฐ๐
I replaced useEffect with use() in React 19. I rewrote three parts of my code. I reverted one.
use() reads a promise in a component. The component waits for the value. You do not need useState. You do not need if loading checks.
This works for two things:
- Data from server components. The server starts the fetch. The client reads it. Code went from 18 lines to 4.
- Promises in context. Pass a promise through context. Read it with use(). This removes null checks.
But it fails for polling.
I tried to use use() for a status check every 5 seconds. It did not work. I needed to cancel the call. I needed to trigger it again. My code became longer and had bugs.
I went back to useEffect.
Follow this rule:
- Use use() for promises with one resolution.
- Use useEffect for things with multiple resolutions.
- Use useEffect for polling, websockets, and subscriptions.
use() is a tool for reading. It is not a tool for managing lifecycles.
New features are not magic. They are tools for specific jobs. Test one example before you refactor your whole app.