How to disable button in React.js

后端 未结 8 1821
迷失自我
迷失自我 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:35

    this.input is undefined until the ref callback is called. Try setting this.input to some initial value in your constructor.

    From the React docs on refs, emphasis mine:

    the callback will be executed immediately after the component is mounted or unmounted

提交回复
热议问题