We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I want to listen to the property change, and then update the store, however it doesn't work. any workaround?
Here is my code: ` import React from 'react'; import Store from './MyStore';
// Re-render the component when the store updates.
function MyComponent() { let store = Store.useStore();
React.useEffect(() => { store.on('one').subscribe((one) => { console.log(store); store.set('sum')(store.get('one') + store.get('two')); });
store.on('two').subscribe((two) => { console.log(store); store.set('sum')(store.get('one') + store.get('two')); });
}, []);
return (
function NumberInput({ storeKey, value }) { let store = Store.useStore();
return ( <input onChange={(e) => store.set(storeKey)(parseInt(e.target.value, 10))} type="number" value={value} /> ); }
export default Store.withStore(MyComponent);
`
` import { createConnectedStore } from 'undux';
let initialState = { one: 0, two: 0, sum: 0, };
export default createConnectedStore(initialState);
The text was updated successfully, but these errors were encountered:
https://undux-readme-demo-js-mgnrwt.stackblitz.io
Sorry, something went wrong.
No branches or pull requests
I want to listen to the property change, and then update the store, however it doesn't work.
any workaround?
Here is my code:
`
import React from 'react';
import Store from './MyStore';
// Re-render the component when the store updates.
function MyComponent() {
let store = Store.useStore();
React.useEffect(() => {
store.on('one').subscribe((one) => {
console.log(store);
store.set('sum')(store.get('one') + store.get('two'));
});
}, []);
return (
<NumberInput storeKey="one" value={store.get('one')} />
<NumberInput storeKey="two" value={store.get('two')} />
Sum: {store.get('sum')}
);
}
function NumberInput({ storeKey, value }) {
let store = Store.useStore();
return (
<input
onChange={(e) => store.set(storeKey)(parseInt(e.target.value, 10))}
type="number"
value={value}
/>
);
}
export default Store.withStore(MyComponent);
`
`
import { createConnectedStore } from 'undux';
let initialState = {
one: 0,
two: 0,
sum: 0,
};
export default createConnectedStore(initialState);
`
The text was updated successfully, but these errors were encountered: