How to disable a button in React

Let's assume that we want to disable a button after counter = 10. You can use the disabled button property to set the condition.

javascript
import React, { useState, useEffect } from 'react';

const Counter = () => {
    
    const [counter, setCounter] = useState(0);
    
    return(
        <button onClick = {() => setCounter(counter + 1)} disabled = {counter === 10}>Click</button>
    );
}

export default Counter;

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.