How to disable input field on button click in react?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

Today, I am going to show you. How to disable input field on button click in react with code example.

If we want to disable our button after clicking on it, We can disable it by using react’s state. We will set the button’s disable state to false on load and add the onClick function in our button element, which will set the button’s disable state to true. So, When a user clicks on the button, it will change its disable state to true.

Let’s look at the following example to understand how it basically works:


import React from "react";
function DisableAfterClick() {
  const [disable, setDisable] = React.useState(false);

  return (
    <button disabled={disable} onClick={() => setDisable(true)}>
      Click to Disable!
export default DisableAfterClick

Check the output of the above code example.

React App, Input, Disable

React App, Input, Disable

All the best 👍

Premium Content

You can get all the below premium content directly in your mail when you subscribe us


Portfolio Template

View | Get Source Code

Cheat Sheets

Cheat Sheets Books are basically Important useful notes which we use in our day-to-day life.

I'm working on some more Cheat Sheets book on Jquery, TypeScript, React js and for other languages. I will send it once it's completed.

Stay tuned working on React Js Cheat Sheets Book

Related Posts