-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
13 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,17 +11,18 @@ import history from './routerHistory'; | |
|
||
const Route1 = <h1>Hello</h1>; | ||
const Route2 = <h1>World</h1>; | ||
const location = atomWithLocation(); | ||
location.onMount = (set) => { | ||
const callback = (arg) => { | ||
const searchParams = new URLSearchParams(arg.location.search); | ||
const loc = { searchParams, ...arg.location }; | ||
set(loc); | ||
}; | ||
const unlisten = history.listen(callback); | ||
callback(history); | ||
return unlisten; | ||
}; | ||
const location = atomWithLocation({ | ||
subscribe: (arg) => { | ||
const callback = (callbackArg) => { | ||
const searchParams = new URLSearchParams(callbackArg.location.search); | ||
const loc = { searchParams, ...callbackArg.location }; | ||
//set(loc); // how do I set the atom from in here? | ||
}; | ||
const unlisten = history.listen((listenArg) => {}); | ||
callback(history); | ||
return unlisten; | ||
}, | ||
}); | ||
|
||
const App = () => { | ||
const loc = useAtomValue(location); | ||
|
@@ -34,7 +35,7 @@ const App = () => { | |
flexDirection: 'column', | ||
gap: '16px', | ||
}} | ||
> | ||
> | ||
{/* @ts-expect-error */} | ||
Check failure on line 39 in examples/04_react_router/src/App.tsx GitHub Actions / test
|
||
<UNSTABLE_HistoryRouter history={history}> | ||
Check failure on line 40 in examples/04_react_router/src/App.tsx GitHub Actions / test
|
||
current pathname in atomWithLocation: "{loc.pathname}" | ||
|