I'm trying to make a simple app that counts the number of times the button has been clicked. I read this is a good first question in JS interviews. "Ask the candidate to build a click counter using any popular framework (React preferred in 2020). This ridiculously simple app has one job: keep track of how many times the user has clicked the button during the current session. No storage. No network I/O. Just count clicks. It is intentionally ridiculously simple" My first instinct would be to use hooks, but the question wants the programmer to do it without using storage which I believe includes using state.
import React from 'react';
import './App.css';
function App() {
let count=0;
const add=()=>{
debugger;
count++;
}
return (
<header className="App-header">
<button onClick={()=>add()}>click me</button>
{count}
</header>
);
}
export default App;
Here is what I tried. Using debugger I can see count does go up but the changes aren't showing on the page. Any advice would be appreciated.