Sometimes we have one state and its value will be changed if and only if another state is changed. Nowadays we have to update their states manually in actions, for instance:
{
state: {
num: 3,
sqauredNum: 9
},
actions: {
setNum: num => {
return state => {
state.num = num
state.sqauredNum = num * num
}
}
}
}
Is there a way to manage only core states and make the derived states (like sqauredNum) be re-calculated automatically (like Selectors in https://recoiljs.org/docs/introduction/core-concepts)
const defaultFunc = () => {}
{
state: {
num: 3,
sqauredNum: ({ num }) => num * num // calculated state
func: defaultFunc // function handler
}
}
...
const App = () => {
const [{ sqauredNum }] = useStore('xxx')
// use sqauredNum
}
Sometimes we have one state and its value will be changed if and only if another state is changed. Nowadays we have to update their states manually in actions, for instance:
Is there a way to manage only core states and make the derived states (like
sqauredNum) be re-calculated automatically (like Selectors in https://recoiljs.org/docs/introduction/core-concepts)