top | item 43616281

(no title)

veidelis | 10 months ago

"This is the famous UI = f(state) mental model of React". Famously incorrect generalization. Why? For example, the useRef hook enables components to hold their own state. React components are not guaranteed to be pure functions. Of course, it can depend on how one writes their code, but it's not a guaranteed that UI = f(state) in React in general.

discuss

order

guhidalg|10 months ago

It's a mental model, not how it works. Your computer isn't actually executing C code, but it's helpful to think that it does.

If you write React code that strays from that model, you better know what you're doing. When I have to reach for `useRef`, I know that I'm in dangerous water.

10000truths|10 months ago

This is needlessly pedantic. useRef/useEffect are tools to implement the model on top of an imperative reality. Things like canvas rendering APIs don't have a pure interface, but it's still obviously very useful to provide one (hence libraries like react-konva and react-three-fiber).

ketzo|10 months ago

"All mental models are incorrect; some mental models are useful"