skip to Main Content

I have an input element listening to an event, how do I pass the value of the input to a React State?

const [business, setBusiness] = useState('Value should be entered here')

<input placeholder="Search Businesses" onChange={"pass the value"}/>

2

Answers


  1. Something like that:

    <input placeholder="Search Businesses" onChange={e => setBusiness(e.target.value)}/>
    
    Login or Signup to reply.
  2. One can set value in useState by setting event value like this :

    <input placeholder="Search Businesses" onChange={event => setBusiness(event.target.value)}/> 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search