Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

usestate with string

// usestate with string

const [name, setName] = useState('')
const onChange = (e) => {
  setName(e.target.value)
}

return (
  <>
    <form>
      <input type="text" onChange={onChange} value={name} />
  // or   <input type="text" onChange={(e) => setName(e.target.value)} value={name} />
    </form>
    <h2>{name}</h2>
  </>
);
 
PREVIOUS NEXT
Tagged: #usestate #string
ADD COMMENT
Topic
Name
3+5 =