-
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.
feat: useUrlState can handle multiple useUrlState updates simultaneously
- Loading branch information
1 parent
bafd70d
commit 39d75cd
Showing
6 changed files
with
145 additions
and
43 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
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
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