Published on

JSXのreturnの中で分岐処理を処理したい

Authors

みそ

render() {return()}の中で以下のコードを追加する

{(() => {jsコード})()}

render() {
  return (
    {(() => {
      if (thisWorld) {
        return (
          <>
           <div>Hello World!</div>
          </>
        )
      } else {
        return (
          <>
            <div>Gatsby World!</div>
          <>
        )
      }
    })()}
  )
}

ただし、分岐処理などは別に切り出して関数かするのがベストです。