0
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 3 years have passed since last update.

【React】'Hoge' is defined but never used no-unused-varsの対処法

Posted at

症状

reactアプリをnpm startしたときに以下のような警告が表示されてしまいました。 特に動作に問題ないので放置していたところ、何百行分も出力されるようになってしまったため対処することにしました。

内容を翻訳すると、「「Hoge」は定義されていますが、使用されることはありません」となりました。
どうやら使われない変数だったり、importしたものがあったりすると、親切心からそれを教えてくれるようです。

warn
Line 1:16:  'Hoge' is defined but never used  no-unused-vars
Fuga.jsx
import React,{useState} from "react";
import Hoge from "../Hoge";

export const Fuga = () => {
  const [count,setCount] = useState(0)

  function addCount() {
    setCount(count + 1);
  }

  return (
    <div>
      <button onClick={() => addCount()}>
      {count}
    </div>
  )
}

解決方法

使われていないimportを消したら解決しました。
Fuga.jsx
import React,{useState} from "react";

export const Fuga = () => {
  const [count,setCount] = useState(0)

  function addCount() {
    setCount(count + 1);
  }

  return (
    <div>
      <button onClick={() => addCount()}>
      {count}
    </div>
  )
}
0
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
0
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?