using the callback to <Show> and update store, results in whole store being set to new value
if I do this in form
setFormDataStore({ companyDetails: { phoneNumber: e.currentTarget.value } });
then the only value in the store is as follows: causing other part to throw undefined errors19 Replies
that's how setStore works, you want
setStore("companyDetails", {...})
yeh , but in another case it wasn't doing that in a simpler app
repro
here i was awas updating address and the company name wasn't touched
but what you say makes sense
setStore merges top level values
so much black box with stores, i can barely take it
very hard for people to pick this up
when you do
setStore({})
nothing happens
but setStore({ a: {} })
replaces a
completely with new objectsi see
it's a few things to keep in mind
most of the times, you want to set values through path
path doesnt work in this case
cause of the callback
wdym?
it should work unless the value at the path doesn't exist yet
and you want to set nested prop
e.g
createStore({})[1]("a", "b", 1)
in such cases, produce or reconcile is better optionexport const [formDataStore, setFormDataStore] = createStore<CompanyCaseDetails | {}>();
| {} to get round the types
basically this
intermediate value doesn't exist yet
dont understand
intermediate value ?
but you can
setStore("companyDetails", { ... })
kinda chicken and egg issues
using
<CompanyCaseDetails | {}>
gets around a lot of initial typing issues, but just gives you a bunch more afterwords
ill just ts ignore fo rnow