mirror of
https://github.com/facebook/react.git
synced 2026-02-26 18:58:05 +00:00
22 lines
430 B
JavaScript
22 lines
430 B
JavaScript
import React, { useState } from 'react';
|
|
|
|
export default function Toggle() {
|
|
const [show, setShow] = useState(false);
|
|
return (
|
|
<>
|
|
<h2>Toggle</h2>
|
|
<div>
|
|
<>
|
|
<button onClick={() => setShow(s => !s)}>Show child</button>
|
|
{show && ' '}
|
|
{show && <Greeting>Hello</Greeting>}
|
|
</>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
function Greeting({ children }) {
|
|
return <p>{children}</p>;
|
|
}
|