Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

disable a button react

// Input field listens to change, updates React's state and re-renders the component.
<input onChange={e => this.setState({ value: e.target.value })} value={this.state.value} />

// Button is disabled when input state is empty.
<button disabled={!this.state.value} />
Comment

disable button in jsx

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>
Comment

DisableButton in React js

import {useRef} from 'react';
let btnRef = useRef();

const onBtnClick = e => {
  if(btnRef.current){
    btnRef.current.setAttribute("disabled", "disabled");
  }
}

<button ref={btnRef} onClick={onBtnClick}>Send</button>
Comment

PREVIOUS NEXT
Code Example
Javascript :: pipe data to json angular 
Javascript :: dart code formatter vscode 
Javascript :: javascript split string into array by comma 
Javascript :: placeholder in angular 9 select 
Javascript :: define function to get random value from array 
Javascript :: vuejs props 
Javascript :: json objects 
Javascript :: Javascript console log a string 
Javascript :: remove item at index in array javascript 
Javascript :: javascript response redirect 
Javascript :: javascript foreach example 
Javascript :: javascript how to get middle letters of a string 
Javascript :: get object with max value javascript 
Javascript :: express get remote ip 
Javascript :: Simple code example of adding two numbers in javascript 
Javascript :: encrypt javascript node 
Javascript :: javascript print path 
Javascript :: sum all numbers in a range javascript 
Javascript :: how to concatenate strings javascript 
Javascript :: React count up on scroll 
Javascript :: document get elements by id js 
Javascript :: force rerender react 
Javascript :: axio post file 
Javascript :: jquery element width 
Javascript :: toastify 
Javascript :: round number at 2 decimal places 
Javascript :: string concatenation javascript 
Javascript :: discord js bot embed user profile picture 
Javascript :: get font size jquery 
Javascript :: fetch api in js 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =