forked from alibaba/hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/alibaba/hooks
- Loading branch information
Showing
12 changed files
with
264 additions
and
141 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* title: Limit maximum history length | ||
* desc: Limit the maximum number of history records to avoid excessive memory consumption. | ||
* | ||
* title.zh-CN: 限制历史记录最大长度 | ||
* desc.zh-CN: 限制最大历史记录数量,避免过度占用内存。 | ||
*/ | ||
|
||
import { useHistoryTravel } from 'ahooks'; | ||
import React from 'react'; | ||
|
||
export default () => { | ||
const maxLength = 3; | ||
const { value, setValue, backLength, forwardLength, back, forward } = useHistoryTravel<string>( | ||
'', | ||
maxLength, | ||
); | ||
|
||
return ( | ||
<div> | ||
<div>maxLength: {maxLength}</div> | ||
<div>backLength: {backLength}</div> | ||
<div>forwardLength: {forwardLength}</div> | ||
<input value={value || ''} onChange={(e) => setValue(e.target.value)} /> | ||
<button disabled={backLength <= 0} onClick={back} style={{ margin: '0 8px' }}> | ||
back | ||
</button> | ||
<button disabled={forwardLength <= 0} onClick={forward}> | ||
forward | ||
</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
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
Oops, something went wrong.