Aug 8, 2017 · 1 min read
You are correct. There are some tricks to storing state. That is what a lot of FP is about, How to manage mutations and state. Everything cannot be pure. There are some fun things you can do with this too. For example, check out this Counter block:
const Counter = (state = 0) => () => state++The state is encapsulated in a closure, and then returned as a function. Every time that function is called, it mutates the encapsulated state.
You would create it like this:
const counter = Counter(0)counter() // => 0
counter() // => 1
counter() // => 2
counter() // => 3
We have just created a Counter that holds state and without any globals!
It is similar to a poorman’s redux.
