<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Change</title>
</head>
<body>
<div class="root"></div>
</body>
<script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script src="https://unpkg.com/prop-types@15.7.2/prop-types.js"></script>
<script type="text/babel">
const root = document.querySelector(".root");
function Btn({text, changeValue}) {
return (
<button
onClick={changeValue}
style={{
color: "black",
border: "0",
borderRadius: "10px",
backgroundColor: "gray",
padding: "0px 10px",
}}
>
{text}
</button>
);
}
function App() {
const [value, setValue] = React.useState("Save Changes");
function changeValue() {
setValue("Revert Changes");
}
return (
<div>
<Btn text={value} changeValue={changeValue}/>
<Btn text={setValue}/>
</div>
);
}
ReactDOM.render(<App />, root);
</script>
</html>
카테고리 없음