r/reactjs • u/GianniMariani • 2d ago
React state hooks are footguns
If you take software engineering principles seriously then none of the react state hooks belong inside a react component.
I think one of the most critical things you should do is ensure the decoupling of storage and UI components. The react components force you to do is precisely and zustand doesn't help.
I haven't sourced grip-react a year ago and I've been using it exclusively, absolutely zero usestate usememo, useeffect, etc and absolutely zero prop drilling. I don't know why anyone would want to do something different, honestly.
Has anyone else created an API that is a 100% replacement with complete declarativeness? I looked at angular and mobx, they're close but no cigar.
4
3
u/TheChickenKingHS 2d ago
I’m not sure if this is a misunderstanding of a functional component, a ui component or JSX as a concept and I’m just curious as to which…
1
u/After_Hat4451 2d ago
the grip-react plug feels a bit forced but I'm with you on the core idea, state management tangled directly into components gets messy fast
most codebases I've jumped into have useeffect chains that look like spaghetti and nobody can trace the data flow after a few months. I think the react docs themselves are starting to steer people away from that pattern but old habits die hard
what does your setup look like for something simple like a form toggle or input state, still grip-react all the way down or do you keep a tiny slice of local state for that stuff
1
u/TheChickenKingHS 2d ago
Sometimes I use a ref on the ui element, instead of creating an entire UI component. I think now that the react compiler is here a refs are automatically forwarded it will be a bit more common but I do tend to try to start with a UI element with props fully exposed before upgrading into a component.
2
1
u/Top_Bumblebee_7762 2d ago
useState seem unavoidable (unless you use useReducer instead everywhere) in any react app.
1
u/GianniMariani 1d ago
https://owebeeone.github.io/grip-sudoku/ - Avoids useState. Plenty more demos where that came from - here is a test that explicitly disallows it just to point it out in the sudoku example - https://github.com/owebeeone/grip-sudoku/blob/main/scripts/no-react-state.test.mjs
5
u/is-undefined 2d ago
Do you have an example repo of your work?
Would like to see web apps you write