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

> The key is using React hooks with pure components, and eschewing the lifecycle altogether.

Can someone explain this in a little more detail? Particularly the eschewing the lifecycle altogether. Does this basically mean delaying the view render until all the business logic is evaluated, aiming for only one render per operation?




>Can someone explain this in a little more detail? Particularly the eschewing the lifecycle altogether.

We use it in conjunction with MobX observers, so that a component is only ever rerendered when its' data is updated, and there's no fooling around with `componentDidUpdate` stuff that can get unwieldy really fast.

The interaction flow is basically: Click handler -> Send event to the state machine -> State machine evaluates business logic, calls services, etc. and updates MobX model -> MobX observer rerenders the pure functional React component. So that all your components are ever doing is sending events to the state machine, with no business logic baked in. Use `useState` for ephemeral component level state like toggle switches, but the source of truth for the entire application lies in MobX models updated by state machines.




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

Search: