3 ms·
They are _not_ pure functions. A pure function will return the same value for the same arguments every time. This is not true of functional components using hoo
by joshfee 5y ago
They are _not_ pure functions. A pure function will return the same value for the same arguments every time. This is not true of functional components using hooks as the data received from calling the hook can change over time due to side effects.
- imbnwa 5y agoA thought that occurs to me is that React Hooks are Facebook engineering's attempt at an Effect monad in JS that isn't well-typed
- kristiandupont 5y agoDan goes into the topic of algebraic effects in this excellent blogpost: https://overreacted.io/algebraic-effects-for-the-rest-of-us/ https://overreacted.io/algebraic-effects-for-the-rest-of-us/
- imbnwa 5y agoThank you for this, will take a look
- phailhaus 5y ago> A pure function will return the same value for the same arguments every time. Yes, and given the same outputs provided by props + hooks, components will return the same value. That's why you can write hooks functionally, and why we can do away with class-based functions entirely. With the exception of refs, there is no actual internal state that your component needs to deal with.