Hacker News new | past | comments | ask | show | jobs | submit login

Having a good way to compose stateful behaviour in React components is really useful. The alternative is a mess of higher-order components which quickly gets very annoying and tedious. Hooks provide that ability, and they make a lot of cases much easier to write.

Hooks also have some behaviour that makes them harder to understand in certain situations. Closures are quite easy to get wrong, and handling callbacks is quite annoying because they're not stable by default.

I think the timeout example is not ideal, it uses useEffect to handle an event, which is not the way this is supposed to be done and which does lead to various complications. But timeouts are the kind of thing that is much more difficult in hook-based React than it should be. But I don't think this is representative, it's a bit more like a worst case for React for things that should be simple but aren't. You don't write timers all day, you put this in a hook once and write other stuff.




There should be a meme for "useEffect is not an async framework".




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: