2
5

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.

Reactでpropsを渡すときに使う「...」ドット3つ

Last updated at Posted at 2019-04-16
render() {
 const obj = {
            a:1,
            b:2
        }

 return (
 <Component {...obj} />
 )
}

なんか気持ち悪いなと思ったらjsx(React.jsでhtmlをつくること)特有の書き方らしい。
以下のようにして書くのと同じこと。
(訂正 2019.11.10 これはスプレッド構文というJavaScriptの機能で、Reactは特有の書き方ではありませんでした。kouhe1さんご指摘ありがとうございます。)

render() {
 const obj = {
            a:1,
            b:2
        }

 return (
 <Component a={1} b={2} />
 )
}

ひとつひとつpropsを定義してあげて渡すか、
オブジェクトを展開してあげてまとめて渡すかの違い。

2
5
1

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
2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?