bcherny / undux

⚡️ Dead simple state for React. Now with Hooks support.

Home Page:https://undux.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

undux usage outside of react

andykais opened this issue · comments

Hi! I have a cli program that is constantly updating at different intervals. Undux would be a great fit for it, but it is heavily coupled to react. Is there a way to use an undux store outside of a react component, or is something like that in the works? Something like

const store = createIndependentStore({ a: 0, b: 0 })

store.on('a').subscribe(/* do something */)
store.set('a')(1)
store.get('a')

Hey there @andykais! I think what you want is createStore.

I marked it deprecated, but there seem to be enough use cases that we’re going to un-deprecate it and keep it around.

great! One other bit on this is that undux requires react internally. This does not affect bundle size by much, but it is unnecessary and confusing to someone looking at the package.json of a project like I have proposed, and seeing react inside it. A possible solution would be only requiring react for createConnectedStore and not createStore.

screenshot 149

Yeah, the problem is that we export the React connector from index.ts, to address a peculiarity of the module bundler we use internally at facebook.

I agree it would be good to decouple the React-specific stuff more. Someone proposed a way to do that in #62