I’m trying my best to figure out React, and I’m attempting to make a simple counter, but StackBlitz is continually throwing the error in the title. I have a object in my HTML as <button onclick="button">.
First, I tried putting the onclick in the HTML that gets returned, but I can’t get that to work right without the editor yelling at me for code blasphemy, or something. Second, I tried, just in-case it was something that was wrong with clicks += 1 and it not telling me, switching += to =+, and making the clicks variable into countValue, but nothing did anything.
My code in app.tsx is: (and apologies if it sucks, i have next to no idea what im doing)
var clicks = 0
function handleClicks() {
clicks += 1
return (<button>
{clicks}
</button>
);
}
My HTML is as follows:
<html>
<body>
<button onclick="HandleClicks()" class="button">
Button
</button>
</body>
</html>
and, my main.tsx, which was already there when i started the project:
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)