How to disable button in React.js

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

    very simple solution for this is by using useRef hook

    const buttonRef = useRef();
    
    const disableButton = () =>{
      buttonRef.current.disabled = true; // this disables the button
     }
    
    
    

    Similarly you can enable the button by using buttonRef.current.disabled = false

提交回复
热议问题