3 ms·
Maybe it won't be an issue. However, it does go against regular advice of being explicit over magical. Depending on call order is something that immediately pop
by emerongi 8y ago
Maybe it won't be an issue. However, it does go against regular advice of being explicit over magical. Depending on call order is something that immediately pops out as fishy.
As always, programming is about trade-offs and the React team is claiming this trade-off is worth it.
- ricardobeat 8y agoApparently React's internals have been doing similar order-based magic for a while already.
- Vinnl 8y agoThat's also the reason why you have to make sure you're passing an update function to `setState` sometimes.
- jontro 8y agoThat's not why you have to do it, it's because the state can be updated asynchronously. It's only applicable when you try to update the state based on previous state or props values.
- joesb 8y agoIf you have a stack machine, when you write a function like this. function foo() { let x = 1; let y = 2; x + y; } Your code already depends on ordering. x is on the stack first. y is on the stack second. You don't randomly rewrite this two lines of code on every invocation of foo. `let x = 1` and `let [x] = useState(1)` is the exact same thing.
- deleted 8y ago[deleted]