Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Add a reset history method to useStateWithHistory

オープン
#2,519 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
48/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
react, typescript
領域
frontend

調査の方向性

Start by locating the TypeScript implementation and tests for useStateWithHistory, then compare its API with useUndoable's resetInitialState. Add a reset method that accepts the new state, makes it the sole history entry, and leaves rewinding unable to reach the previous initial value; update or add tests for the reset behavior.

索引モデルが issue の本文から書いたものです。

説明

Is your feature request related to a problem? Please describe.
useUndoable has a great summary of why resetting state on useStateWithHistory is useful. I set my state to the response of a network request and want to prevent the user being able to rewind history to the initial value set before the request had finished.

Describe the solution you'd like
Add a method to useStateWithHistory that follows the API of useUndoable's resetInitialState, where it takes in a param to set the state to and clears the history.

Describe alternatives you've considered
There are two alternatives I've been using:

  1. using useUndoable instead of this library (but it doesn't work for deeply nested objects and is an additional dependency)
  2. Manually extending the useStateWithHistory myself to include this method. The method is really easy to add:
  const resetInitialState = useCallback(
    (newInitialState: IHookStateInitAction<S>) => {
      innerSetState(newInitialState as S);
      history.current = [newInitialState as I];
      historyPosition.current = 0;
    },
    [],
  );

This seems to have been requested already in https://github.com/streamich/react-use/issues/1386 but I'm re-raising here because:
I believe the interface of useUndoable is relevant, I'm providing a proposed solution, and that issue has been open for over 2 years.

If approved i'd even be happy to raise a PR myself.

Thanks!

主要言語
TypeScript
スター
44k
フォーク
3.3k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

streamich/react-use のほかの issue

streamich/react-use の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。