in packages/recoil-sync/__test_utils__/RecoilSync_MockURLSerialization.js [24:64]
function TestURLSync({
storeKey,
location,
browserInterface,
}: {
storeKey?: string,
location: LocationOption,
browserInterface?: BrowserInterface,
}): React.Node {
const serialize = useCallback(
items => {
const str = nullthrows(JSON.stringify(items));
return location.part === 'href'
? `/TEST#${encodeURIComponent(str)}`
: str;
},
[location.part],
);
const deserialize = useCallback(
str => {
const stateStr =
location.part === 'href' ? decodeURIComponent(str.split('#')[1]) : str;
// Skip the default URL parts which don't conform to the serialized standard.
// 'bar' also doesn't conform, but we want to test coexistence of foreign
// query parameters.
if (stateStr == null || stateStr === 'anchor' || stateStr === 'foo=bar') {
return {};
}
return JSON.parse(stateStr);
},
[location.part],
);
useRecoilURLSync({
storeKey,
location,
serialize,
deserialize,
browserInterface,
});
return null;
}