recoil-sync questions #2081
Replies: 2 comments
-
The quoting or other encoding is not part of the core
Someone did create an adapter layer from Refine to another similar library. I forget the name off-hand.. But, perhaps a similar solution could work here?
Yes, the
One option is to break this up into separate atoms. You can also create custom read/write callbacks in
If you want mounting a component to have side-effects for setting state then would
Not sure what you mean by "dynamically"? It is called for each member in the family, so you could theoretically have a different type for each atom in the family based on the family parameter. |
Beta Was this translation helpful? Give feedback.
-
Thank you for answering these questions.
I'm not sure if I can break this up into separate atoms. Is there any way to do something like the following? const formState = atom({
key: 'formState',
default: {
field1: 1, // number
field2: "2", // string
field3: true, // boolean
},
});
const formFieldStateSelector = selectorFamily({
key: 'formFieldStateSelector',
get: field => ({get}) => get(formState)[field],
});
const field1Atom = atom({
key: 'field1Atom',
default: formFieldStateSelector('field1') // <- I wanna do something like this to break this up into separate atoms
})
What I meant is that const formState = atom({
key: 'formState',
default: {
field1: 1, // number
field2: "2", // string
field3: true, // boolean
},
});
const formFieldStateSelector = selectorFamily({
key: 'formFieldStateSelector',
get: field => ({get}) => get(formState)[field],
});
// use atomFamily here to use atom effect
const formFieldState = atomFamily({
key: 'formFieldState',
default: formFieldStateSelector,
effect: (field) => [
urlSyncEffect({ refine: /* I wanna define refine dynamically; number() for field1, string() for field2 etc */, // <- here
history: 'replace', storeKey: 'query'
})
]
}); |
Beta Was this translation helpful? Give feedback.
-
First, thank you for creating these great libraries.
I got some questions while I was developing with Recoil.
""
from query params when refine type is string? Currently it's like?query="value"
, it would be nice to have?query=value
. That would be ideal to handle query params like query-stringrefine
?field1
andfield2
as query params.Beta Was this translation helpful? Give feedback.
All reactions