Custom hook example has missing dependency
オープン
初心者向け
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 11.8k
- フォーク
- 7.9k
- 平均マージ
- 1日 11時間
- マージ済み PR(30日)
- 11
説明
Regarding 'Building Your Own Hook' page (github link).
Small but critical mistake in custom hook example for function useFriendStatus(). It needs a dependency. I.E.
Change line 91 by inserting , [friendID].
Without the dependency this appears to be 'magic'. I found I had to add a dependency when writing my learning hook, otherwise my counter just spins indefinitely.
Example
Custom hook:
function useCounter(targetId: string) {
const [counter, setCounter] = useState(0);
useEffect(() => {
setCounter(counter+1);
}, [targetId]);
return counter;
}
Client code:
interface MainProps {
counterTargetId: string;
}
export default function MainPage(props: MainProps = {
counterTargetId: 'a',
}) {
const currentCount = useCounter(props.counterTargetId);
return (<div>
<p>
Count: {currentCount}
</p>
</div>);
}
function App() {
const [targetId, setTargetId] = useState('a');
return (
<div className="App">
<input
type="button"
value="Toggle"
onClick={() => setTargetId(targetId === 'a' ? 'b' : 'a')}/>
<MainPage counterTargetId={targetId}/>
</div>
)
}
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
content/docs/hooks-custom.md を開き、91 行目付近にある useFriendStatus() の例を確認します。説明されているとおりに例の依存関係リストを更新し、その後、ドキュメントが正しくレンダリングされ、例に意図した依存関係が表示されることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, react
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 1/5
- 見積もり時間
- 1時間未満
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 70/100