i use node.js in my HTML file using tag now how do i use useState with it I tried:
const {useState} = React
Here is my code
const {useState} = React;
function App(){
const {text, setText} = useState("Hello world")
console.log(text);
function handleClick(){
setText("Hello universe")
}
return <h1 onClick={handleClick}> {text} </h1>
}
ReactDOM.render(<App />, document.getElementById('root'))
CodePudding user response:
Your initial state is set up slightly wrong
change
const {text, setText} = useState("Hello world")
to this
const [text, setText] = useState("Hello world")