Conditional rendering
Show or hide things with && and ? :
Key points
- You can't write if inside { } in JSX. Use && or ? : instead
- To show or hide something, use &&: {isOpen && <p>Content</p>}
- To show either A or B, use ? :: {isLoggedIn ? <p>Welcome</p> : <p>Please log in</p>}
Try it
- Make the text shown when open two lines long
- Show "Closed" only when it's closed (hint: !isOpen &&)
- Make it start out open (hint: the initial value of useState)