Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For my learning, what kind of state management do you use or see commonly used with web components?


I currently have three large components that handle state between them, and a bunch of control components that don't care about state (they receive values as attributes, and trigger "change" events if changed by the user).

The larger components contain their own state, and communicate by events (so component Foo emits a change event when its state changes, and component Bar listens for that event and fetches the new state by checking event.target.data).

It's working reasonably well with this relatively small set of interactions. But I can see a point where I'll have to create a Flux/Vuex-style state store and use actions to mutate it.


I use something similar to React class components. Under the hood my set function calls Object.assign and I debounce the render function callback. You could implement it yourself in <80 lines of JavaScript[0]. I'm not sure what other people use but I've been using this style of state management for ~4 years and it's been fine so far.

[0]: https://github.com/codewithkyle/supercomponent/blob/master/s...

Edit: if signals are your jam you could us https://github.com/maverick-js/signals




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: