Skip to content

Commit

Permalink
Merge pull request alibaba#888 from alibaba/feat/cache-url-state
Browse files Browse the repository at this point in the history
feat: cache url state
  • Loading branch information
awmleer authored Mar 5, 2021
2 parents db994e5 + 1172b7a commit 56e4560
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/use-url-state/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ export default <S extends UrlState = UrlState>(initialState?: S | (() => S), opt
return parse(location.search, parseConfig);
}, [location.search]);

const targetQuery = {
...initialStateRef.current,
...queryFromUrl,
} as state;
const targetQuery: state = useMemo(
() => ({
...initialStateRef.current,
...queryFromUrl,
}),
[queryFromUrl],
);

const setState = (s: React.SetStateAction<state>) => {
const newQuery = typeof s === 'function' ? (s as Function)(targetQuery) : s;
Expand Down

0 comments on commit 56e4560

Please sign in to comment.