How to disable button in React.js

后端 未结 8 1785
迷失自我
迷失自我 2020-12-01 04:06

I have this component:

import React from \'react\';

export default class AddItem extends React.Component {

add() {
    this.props.onButtonClick(this.input.         


        
8条回答
  •  渐次进展
    2020-12-01 04:47

    You shouldn't be setting the value of the input through refs.

    Take a look at the documentation for controlled form components here - https://facebook.github.io/react/docs/forms.html#controlled-components

    In a nutshell

     this.setState({value: e.target.value})} />
    

    Then you will be able to control the disabled state by using disabled={!this.state.value}

提交回复
热议问题