const buttonRef = useRef(); const disableButton = () =>{ buttonRef.current.disabled = true; // this disables the button } <button className="btn btn-primary mt-2" ref={buttonRef} onClick={disableButton} > Add </button>