| 1 | import * as React from 'react'; |
| 2 | import {useState} from 'react'; |
| 3 | |
| 4 | export default function Toggle() { |
| 5 | const [show, setShow] = useState(false); |
| 6 | return ( |
| 7 | <> |
| 8 | <h2>Toggle</h2> |
| 9 | <div> |
| 10 | <> |
| 11 | <button onClick={() => setShow(s => !s)}>Show child</button> |
| 12 | {show && ' '} |
| 13 | {show && <Greeting>Hello</Greeting>} |
| 14 | </> |
| 15 | </div> |
| 16 | </> |
| 17 | ); |
| 18 | } |
| 19 | |
| 20 | function Greeting({children}) { |
| 21 | return <p>{children}</p>; |
| 22 | } |