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

propsのvalueのデフォルト値はtrue

1
Posted at

next.jsのチュートリアルをやっていてたら、propsのvalue値を省略して書いてあるところがあった。

「そんなことができるのか!?」
「next.jsの仕様なのか!?」

と思って調べてみたところreactの公式にありました。

propのvalueを省略した場合、trueになるようです。以下の2つは同じことを意味してます。

<MyTextBox autocomplete />

<MyTextBox autocomplete={true} />

公式的には、省略することは非推奨。

理由は、es6のオブジェクトのvalueの省略に見えてしまうため混乱するから。
{foo}って書いてあったら、{foo: true}よりも{foo: foo}を普通はイメージするよね!

ってことらしい。

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?