1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ReactでReferenceError useState is not definedが出た時の対処法

Last updated at Posted at 2023-02-10

エラーの背景と解決策

TODOアプリの作成時にuseStateを定義しようとしたら以下のエラーが出ました。

ReferenceError useState is not defined

調べたらimport { useState } from "react";の記述がなかったので
useStateがうまくimportできていない状況でした。

App.jsx
import React from "react";
import "./styles.css";
import { useState } from "react";  //この記述を追記

export const App = () => {
  const [incompleteTodo, setIncompleteTodo] = useState(["ポチ", "(ピーコ"]);
  const [completeTodo, setCompleteTodo] = useState(["ちび"]);
//省略

初歩的でしたが、上記のやり方で解決できました。

資料

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?