xxxxxxxxxx
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
</head>
<body>
<div id="app"></div>
<script type="text/babel">
const { useEffect, useState } = React;
const App = () => {
const [timestamp, setTimestamp] = useState(0);
const reloadPage = () => {
window.parent.location.reload();
};
useEffect(() => {
const currentTimestamp = Date.now();
setTimestamp(currentTimestamp);
}, []);
return (
<div className="container">
<h3>React Js get current timestamp</h3>
<p>Current timestamp: {timestamp}</p>
<button onClick={reloadPage}>Reload Page</button>
</div>
);
};
ReactDOM.render(<App />, document.getElementById("app"));
</script>
<style>
.container {
max-width: 500px;
margin: 0 auto;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
h3 {
font-size: 24px;
margin-bottom: 10px;
}
p {
font-size: 18px;
margin-bottom: 20px;
}
button {
padding: 10px 20px;
font-size: 16px;
background-color: #4caf50;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
button:active {
background-color: #3e8e41;
}
button:focus {
outline: none;
}
</style>
</body>
</html>