1

I'm trying to render multiple React components in a shorthand if, but it doesn't work as expected. This is my source:

  render() {

    const isLoggedin = true; 

    return (
      <div>
        { isLoggedin ? 
            <Greeting />
            <LogoutButton /> 
          : <LoginButton />
        }
      </div>
    );
  }

If I just use one component, it works (for example remove Greeting):

  render() {

    const isLoggedin = true; 

    return (
      <div>
        { isLoggedin ? 
            <LogoutButton /> 
          : <LoginButton />
        }
      </div>
    );
  }

Is there a way to render both of them?

webta.st.ic
  • 4,781
  • 6
  • 48
  • 98

2 Answers2

0

You can use <div> </div> and put a code block there.

e.g.

<div>
<Greeting />
<LogoutButton /> 
</div>
Murat Karagöz
  • 35,401
  • 16
  • 78
  • 107
0

Try this :

render() {

  const isLoggedin = true; 

  return (
    <div>
      { isLoggedin ? (
          <Greeting />
          <LogoutButton />
        ) : (
          <LoginButton />
        )
      }
    </div>
  );
}
GameTag
  • 379
  • 1
  • 12