|
|
|
|
|
by vkazanov
440 days ago
|
|
I had the same question until I understood one key pattern of pure functional programming. Not sure it has a name but here goes. There is world, and there is a model of the world - your program. The point of the program, and all functions, is to interact with the model. This part, data structures and all, is pure. The world interacts with the model through an IO layer, as in haskell. Purity is just an enforcement of this separation. |
|
Functional React follows this pattern. The issue is when the programmer thinks the world is some kind of stable state that you can store results in. It’s not, the whole point is to be created anew and restart the whole computation flow. The escape hatches are the hooks. And each have a specific usage and pattern to follow to survive world recreation. Which why you should be careful with them as they are effectively world for subcomponents. So when you add to the world with hooks, interactions with the addition should stay at the same level