How to fetch time when submit button is clicked from app component. I have two separate component a Timer
component and a App
component.
when i click on submit button from app component it should take current time snapshot from timer component and send it to app component
I don't want to use Submit in timer component
Is it possible to do in React ?
Here is app component
export default function App() {
return (
<div className="App">
<h2>Start editing to see some magic happen!</h2>
<h3>Time: </h3>
<button >Submit</button>
<Timer />
</div>
);
}
Here is Timer Component
export default function Time() {
const [counter, setCounter] = React.useState(0);
React.useEffect(() => {
let countersystem;
countersystem = setTimeout(() => setCounter(counter + 1), 1000);
return () => {
clearTimeout(countersystem);
};
}, [counter]);
return (
<div className="App">
<div>Countdown: {counter}</div>
</div>
);
}