Skip to content
Advertisement

Disabled When Lacking Input in Field in React

I have set of inputs that needs to be filled out completely. I should disable the submit button when its not complete. Its working fine until I decided to erase and fill it out again. It never disables. What would be the proper and correct way to do this? Is there a better way to do this?

CLICK HERE

JavaScript

Advertisement

Answer

To do that, you would instead get disabled state from your child:

  • Adding a new state to your parent component:
JavaScript
  • Pass it down to your child component:
JavaScript
  • Set the status of your button base on that state:
JavaScript
  • Import setDisabled ot your child component and add useEffect like this:
JavaScript

Working Example

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement