1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【useState】ReactのuseStateをわかりやすく話す(ざっくりと)

1
Posted at

ReactのuseStateってなに?をざっくり説明!

今回の話題

よく見るこの形!
const [state, setState] = useState(initialState)

やっていること

useStateのよくある説明
→関数コンポーネントのstateを保持したり、更新したりするためのフック。。。
ーーー
未経験だとちょっとわかりにくい。
結論としては、「state」という変数に「initialState」の値を初期値としてほぞんしときますよ!ということ。

見え方を変えるとこう!
ーーー
const [state, setState] = useState(stateの初期値)

setStateは?

「setState」は関数!
state変数を変化させたいときに「setState」を記述する。

例)

const [state, setState] = useState(0);
const stateUp = () => {
setState(count + 1);
setState(count + 1);
}

実行すると「state=2」なる。

結論

useStateって、変数とその変数を利用する関数の管理をしてくれてるものなんだね!

1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?