How to use two-way binding correctly under react+typescript

for example, if you bind an input value in both directions, is it too low-end to bind only through the onChange event?

Jan.28,2022

typescript binds as native JS binds. Typescript just changes js syntax and does not change react


react is not the v-model syntax sugar of vue, without vue. You need your own onchange to trigger the change of state, and then input value goes to get the state, that is, the controlled component

.
class Demo1 extends Component {
    constructor(props) {
        super(props);
        this.state = {
            value: props.value
        }
    }

    handleChange(e) {
        this.setState({
            value: e.target.value
        })
    }

    render() {
        return (
            <input value={this.state.value} onChange={e => this.handleChange(e)}/>
        )
    }
}
Menu