useStateMachine: A ½ kb state machine hook for React
1–10 of 103 posts
Re: useStateMachine: A ½ kb state machine hook for React
#2Re: useStateMachine: A ½ kb state machine hook for React
#3They encapsulate logic so well and do an amazing job being this isolated data/event source.
I find that I reuse them far more than I reuse components.
Re: useStateMachine: A ½ kb state machine hook for React
#4It’s a little verbose more my liking but I think it could be powerful for large apps with lots of states.
Re: useStateMachine: A ½ kb state machine hook for React
#5Isn't the useReducer hook already an interface for building state machines? The clue is in the signature of reducer functions, the signature as exactly the same as textbook state transition functions...
Re: useStateMachine: A ½ kb state machine hook for React
#6I can't get over how amazing hooks are and how resistant I initially was to them. They encapsulate logic so well and do an amazing job being this isolated data/event source. I find that I reuse them far more than I reuse components.
But they're also soooo idiosyncratic which makes them rather ugly on a general level.
Re: useStateMachine: A ½ kb state machine hook for React
#7Re: useStateMachine: A ½ kb state machine hook for React
#8I can't get over how amazing hooks are and how resistant I initially was to them. They encapsulate logic so well and do an amazing job being this isolated data/event source. I find that I reuse them far more than I reuse components.
They fit so well into React it's crazy. But they're also soooo idiosyncratic which makes them rather ugly on a general level.
But yes, insanely useful once you get the hang of them, they enable forms of abstraction and composability that you'll sorely miss when working in other UI frameworks.
Re: useStateMachine: A ½ kb state machine hook for React
#9Re: useStateMachine: A ½ kb state machine hook for React
#10I can't get over how amazing hooks are and how resistant I initially was to them. They encapsulate logic so well and do an amazing job being this isolated data/event source. I find that I reuse them far more than I reuse components.
* If there’s only useState, then everything is mostly fine. All is good.
* To avoid unnecessary re-rendering you’ll have to move callbacks into useCallback. These callbacks then also need to specify all of their dependencies. So many lines of code that are merely noise.
* They encourage having state locally in the component which often breaks down the moment you slightly tweak the design. So much refactoring!
* Dealing with any other (callback-based, stateful) API is confusing. If you want something to execute once initially you can use useEffect with an empty dependency list, but note that then there’s no way of accessing updates values (in callbacks) and everything will reflect the initial state. Often you’ll have to use useRef just to keep track of the current state. Or maybe useState?
* Debugging is painful. You forget one value in your dependency list and the weirdest things happen. Suddenly you have callbacks running in different rendering scopes with different values.
They feel very “brittle”: Once it works the code looks pretty, but when there’s a slight change of requirements you need to rethink everything.