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

React コンポーネントのプロパティに包含要素無しで複数要素を与えたい

Posted at

元のダメコードです。

import React from 'react';

function Base(props) {
  return (
    <div>
      {props.message}
    </div>
  );
}

export function Specialized(props) {
  return (
    <Base
      message={
        props.message,    値とJSX要素を一緒に指定したい
        <div>element</div>
      }
    />
  );
}

フラグメント使えばいけそうです(元々プロパティへ1要素指定は可能なので、フラグメントを使えば記述方法的に複数個の要素を内包可能)。

      message={
        <>
          {props.message}
          <div>element</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?