This repository was archived by the owner on Jan 1, 2025. It is now read-only.
This repository was archived by the owner on Jan 1, 2025. It is now read-only.
<RecoilURLSync> doesn't reset state if param is not present #1900
Closed
Description
RecoilURLSync{JSON,Transit}
can take a param
if the location
's part
is 'queryParams'
.
However, if the new URL doesn't have the part, RecoilURLSync{JSON,Transit}
doesn't reset a state that syncing it.
for example,
Atom:
const nameState = atom<string>({
key: 'name',
default: '',
effects: [syncEffect({ refine: string() })],
})
App:
function MyApp({ Component, pageProps }: AppProps) {
return (
<RecoilRoot>
<RecoilURLSyncJSON
location={{ part: 'queryParams', param: 'state' }}
>
<Component {...pageProps} />
</RecoilURLSyncJSON>
</RecoilRoot>
)
}
-
access to:
http://localhost:3000/users/1
-
change name state to
'Foo'
, then URL is changed to:
http://localhost:3000/users/1?state=%7B%22name%22%3A%22Foo%22%7D
-
navigate to:
http://localhost:3000/users/2
expected: the name
state is reset to the default (empty string).
actual: the name
state still 'Foo'
.
I think that this line should return empty Map()
instead of null
when stateStr
is null