-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(useUrlState): update docs and test case for multi-state manageme…
…nt (#2125) * feat: useUrlState can handle multiple useUrlState updates simultaneously * fix: change text * fix: do not use promise --------- Co-authored-by: miracles1919 <[email protected]> Co-authored-by: 云泥 <[email protected]>
- Loading branch information
1 parent
4f293c3
commit 0fb401e
Showing
3 changed files
with
103 additions
and
11 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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* title: Multi-state management (split) | ||
* desc: useUrlState can handle multiple useUrlState updates simultaneously | ||
* | ||
* title.zh-CN: 多状态管理 (拆分) | ||
* desc.zh-CN: useUrlState 可以同时处理多个 useUrlState 更新 | ||
*/ | ||
|
||
import React from 'react'; | ||
import useUrlState from '@ahooksjs/use-url-state'; | ||
|
||
export default () => { | ||
const [page, setPage] = useUrlState({ page: '1' }); | ||
const [pageSize, setPageSize] = useUrlState({ pageSize: '10' }); | ||
|
||
return ( | ||
<> | ||
<div> | ||
page: {page.page} | ||
<span style={{ paddingLeft: 8 }}> | ||
<button | ||
onClick={() => { | ||
setPage((s) => ({ page: Number(s.page) + 1 })); | ||
}} | ||
> | ||
+ | ||
</button> | ||
<button | ||
onClick={() => { | ||
setPage((s) => ({ page: Number(s.page) - 1 })); | ||
}} | ||
style={{ margin: '0 8px' }} | ||
> | ||
- | ||
</button> | ||
<button | ||
onClick={() => { | ||
setPage({ page: undefined }); | ||
}} | ||
> | ||
reset | ||
</button> | ||
</span> | ||
</div> | ||
<br /> | ||
<div> | ||
pageSize: {pageSize.pageSize} | ||
<span style={{ paddingLeft: 8 }}> | ||
<button | ||
onClick={() => { | ||
setPageSize((s) => ({ pageSize: Number(s.pageSize) + 1 })); | ||
}} | ||
> | ||
+ | ||
</button> | ||
<button | ||
onClick={() => { | ||
setPageSize((s) => ({ pageSize: Number(s.pageSize) - 1 })); | ||
}} | ||
style={{ margin: '0 8px' }} | ||
> | ||
- | ||
</button> | ||
<button | ||
onClick={() => { | ||
setPageSize({ pageSize: undefined }); | ||
}} | ||
> | ||
reset | ||
</button> | ||
</span> | ||
</div> | ||
<div> | ||
<button | ||
onClick={async () => { | ||
await setPageSize({ pageSize: undefined }); | ||
await setPage({ page: undefined }); | ||
}} | ||
> | ||
reset all | ||
</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