What you have defined here is a functional Component. Only class components can use this
. So either you could change what you have to a class component or you can simply have state in a functional component using the useState
hook like this:
import { useState } from 'react';
export default function TalentSearch() {
const [value, setValue] = useState("value")
return (
<div>
<button onClick={clicked}>click me</button>
<input type="text" name="search" />
<div>
<p>{value}</p>
</div>
</div>
);
}
Some notes
- just call
value
anywhere within the component to get the current state and if you would like to change it use the set state function like this:setValue(new state)
CLICK HERE to find out more related problems solutions.