LoginSignup
0
0

More than 3 years have passed since last update.

Reactひと言メモ(hook)

Last updated at Posted at 2020-10-23

hookとは

クラスコンポーネントでしか扱えなかったライフサイクル(useEffect)、状態管理(useState)を関数コンポーネントでも扱えるようにしたもの。

useContextもあるよ(Redux使わないときに使うかも)

インポートの仕方

import React , {useEffect, useState} from 'react'

useState

//以下のような1行で設定できる。
const [変数名, 関数名] = useState(初期値)

const [abc, setabc] = useState("")
//ステートabcに文字列aaaをセットできる。
setabc("aaa")

useEffect

useEffect(() => {
    //ここに処理
},[依存値])
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