Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

relying on call order does seem kind of scary but without knowing how people structure their code using hooks its hard to know how bad it would be. for example the situation with hooks is basically:

1) any function that calls a hook function has a red colour

2) any function that calls a red coloured function has a red colour

3) if you ever have ever call a red coloured function in a conditional branch then bad things are going to happen

if you have nested functions calling hooks then you can change the order of hooks without even realising hooks are being called which is dangerous. this 'nesting transparency' where callers aren't forced to know about the hook behaviour of their sub-functions is also used as defence in the blog for relying on call order. heh



The "color" you're talking about is the "use" naming convention that's enforced by the linter. So if you call a Hook, you're supposed to call your function `useSomething()`, and we consider it a Hook too.

In practice we haven't seen this to cause confusion from people who actually tried this proposal for more than a few hours.

See https://reactjs.org/docs/hooks-rules.html




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

Search: