Partial Setter for a Store

Is there a way to get a setter function for a nested object inside a store? This is a minimal example of the problem I like to solve. The getter proxy works, but I can't figure out how to get a SetStoreFunction or something else (the props the PersonForm can be changed if needed) that modifies a field inside the store.
const [store, setStore] = createStore({
person: {
name: 'John',
age: 30
},
note: 'foo',
})

return <div>
<PersonForm person={store.person} setPerson={...} />
</div>
const [store, setStore] = createStore({
person: {
name: 'John',
age: 30
},
note: 'foo',
})

return <div>
<PersonForm person={store.person} setPerson={...} />
</div>
2 Replies
Otonashi
Otonashi2y ago
<PersonForm person={store.person} setPerson={(...args) => setStore("person", ...args)} />
<PersonForm person={store.person} setPerson={(...args) => setStore("person", ...args)} />
will do, if you need to satisfy typescript you have to cast, there isn't a better way afaik
Tim Basel
Tim Basel2y ago
Ok, thank you very much.
Want results from more Discord servers?
Add your server