React Hookを使うと書式エラーになる

typescript

Hookを使うとなぜかこんなエラーが

React Hook "React.useState" is called in function "hoge" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use".

理由は単純
“React component names must start with an uppercase letter”とあるとおり
コンポーネント名は先頭大文字じゃないとダメ

export function hoge(){ …

じゃなくて

export function Hoge(){ …
とか
export const Hoge = () => { …
という感じ。

 

コメント

タイトルとURLをコピーしました