-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: merge main branch to v4 (#2528)
* refactor: replace lodash/isEqual with react-fast-compare (#2458) * refactor: replace lodash/isEqual with react-fast-compare * chore: update lock --------- Co-authored-by: 云泥 <1656081615@qq.com> * refactor(useRafInterval): optimize useEffect cleanup fn (#2426) * fix(useAntdTable): 修复动态设置 ready 失效的 bug (#2489) * refactor(useLockFn): catch to finally (#2421) * refactor(useLockFn): catch to finally * refactor(useLockFn): keep the throw e * refactor(createEffectWithTarget): the first parameter is old-deps (#2431) * fix(useCountDown): targetDate resets leftTime (#2346) * chore: update version * fix(type): fixed up some types that are non-standard and errors on `useExteneral` hook (#2508) * fix(type): fixed up some types that are non-standard and errors on `useExternal` hook * style: format * refactor: simplify --------- Co-authored-by: liuyib <1656081615@qq.com> * feat(useStoage): listen to `storage` event (#2298) * feat: sync `storage` state * chore: update test case * refactor: replace StorageEvent to CustomEvent, and add listenStorageChange param * test: revert case in useSessionStorage * docs: modify docs and demo * test: add case for 'enable' parameter * test: remove unnecessary code --------- Co-authored-by: liuyib <1656081615@qq.com> * chore(useLatest): add a default state for comparison in useLatest demo (#2523) * feat(useSelections): support object array (#2485) * feat(useSelections): support object array * fix: solve error * 修复 useAntdTable Params 的类型问题 (#2377) * fix(useAntdTable): change Params filter to filters * docs(useAntdTable): change Params filter to filters * fix(useVirtualList): get correct offset when itemHeight is fixed (#2279) Co-authored-by: huangcheng <huangcheng.lq@bytedance.com> --------- Co-authored-by: Guo Yunhe <i@guoyunhe.me> Co-authored-by: ice <49827327+GetWebHB@users.noreply.github.com> Co-authored-by: guaijie <30885718+guaijie@users.noreply.github.com> Co-authored-by: joe-leong <39672163+joe-leong@users.noreply.github.com> Co-authored-by: 潇见 <xiaojian.lj@antgroup.com> Co-authored-by: Darwish <38754760+LonelyFellas@users.noreply.github.com> Co-authored-by: vaakian <vaakian@gmail.com> Co-authored-by: shanyue <xianger94@gmail.com> Co-authored-by: Conor <729354837@qq.com> Co-authored-by: echo <1558449520@qq.com> Co-authored-by: huangcheng <huangcheng.lq@bytedance.com>
- Loading branch information
1 parent
9e14694
commit 7340355
Showing
23 changed files
with
660 additions
and
148 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
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
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
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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* title: Sync state with localStorage | ||
* desc: When the stored value changes, all `useLocalStorageState` with the same `key` will synchronize their states, including different tabs of the same browser (try to open two tabs of this page, clicking a button on one page will automatically update the "count" on the other page). | ||
* | ||
* title.zh-CN: 将 state 与 localStorage 保持同步 | ||
* desc.zh-CN: 存储值变化时,所有 `key` 相同的 `useLocalStorageState` 会同步状态,包括同一浏览器不同 tab 之间(尝试打开两个此页面,点击其中一个页面的按钮,另一个页面的 count 会自动更新) | ||
*/ | ||
|
||
import React from 'react'; | ||
import { useLocalStorageState } from 'ahooks'; | ||
|
||
export default function () { | ||
return ( | ||
<> | ||
<Counter /> | ||
<Counter /> | ||
</> | ||
); | ||
} | ||
|
||
function Counter() { | ||
const [count, setCount] = useLocalStorageState('use-local-storage-state-demo4', { | ||
defaultValue: 0, | ||
listenStorageChange: true, | ||
}); | ||
|
||
const add = () => setCount(count! + 1); | ||
const clear = () => setCount(); | ||
|
||
return ( | ||
<div style={{ marginBottom: '8px' }}> | ||
<button style={{ marginRight: '8px' }} onClick={add}> | ||
count: {count} | ||
</button> | ||
<button onClick={clear}>Clear</button> | ||
</div> | ||
); | ||
} |
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
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
Oops, something went wrong.