简体   繁体   中英

What is the equal code for OnChange on React Class Component , on React Function Component

what is the equal code for this on React Function Component without using defaultValue?

<input onChange((e)=>{this.setState({title : this.target.value})}) value={value} />

I think this is what your asking:

import { useState } from "react";

function MyComponent({defaultValue}) {
  const [inputValue, setInputValue] = useState(defaultValue);
  return (
    <form>
      <input
        type="text"
        onChange={(e) => setInputValue(e.target.value)}
        value={inputValue}
      />
    </form>
  );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM