Recoil is an experimental state management library for React apps. It provides several capabilities that are difficult to achieve with React alone, while being compatible with the newest features of React.
What is the recommended way to error handle query keys that are synced to recoil atoms via urlSyncEffect? I see we can write a custom Checker which returns a 'success' | 'error' type; however, I'm less sure what the guidance is on how to catch this error?
The use case I have here is that I have a recoil atom with its value synced to the URL. Users might manually try to munge with the URL and hit enter, which could land in an erroneous state.
Example:
My atom:
export const exampleAtom = atomFamily<string[], string | null>({
key: 'exampleAtomKey',
default: [],
effects: () => [
urlSyncEffect({
refine: (value) => {
if (!isValidStringArray(value)) {
return {
type: 'failure',
message: 'myItemKey is not a valid string array!',
path: new Path(),
};
}
return {
value: value as string[],
type: 'success',
warnings: [],
};
},
syncDefault: true,
itemKey: 'myItemKey',
storeKey: 'myStoreKey',
}),
],
});
Here I'm using refine to do my typechecking, but where should this 'failure' type be handled? We have ErrorBoundarys that catch what is thrown, but I'm not seeing a first class way to handle refine failure types specifically.
What is the recommended way to error handle query keys that are synced to recoil atoms via urlSyncEffect? I see we can write a custom
Checker
which returns a 'success' | 'error' type; however, I'm less sure what the guidance is on how to catch this error?The use case I have here is that I have a recoil atom with its value synced to the URL. Users might manually try to munge with the URL and hit enter, which could land in an erroneous state.
Example: My atom:
Here I'm using
refine
to do my typechecking, but where should this 'failure' type be handled? We have ErrorBoundarys that catch what is thrown, but I'm not seeing a first class way to handle refine failure types specifically.Versions I'm using: