Untitled
unknown
plain_text
3 years ago
976 B
60
Indexable
<html>
<head>
<title>counter</title>
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"> </script>
</head>
<body>
<div id="mydiv"></div>
<script type="text/babel">
import React, { useState, useEffect } from 'react';
function Example() {
const [count, setCount] = React.useState(0);
// Similar to componentDidMount and componentDidUpdate:
useEffect(() => {
// Update the document title using the browser API
document.title = `You clicked ${count} times`;
});
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}
ReactDOM.render(<div><Example/></div>,document.getElementById("mydiv"));
</script>
</body>
</html>
Editor is loading...