Skip to content
Advertisement

I can’t change the state of the input tag when click on submit button and when it’s empty of fill with text?

Here I built a form and I want, when I click on submit button
if title part(input with id form-title) is empty border of the input gets a specific className but
It doesn’t work
I uploaded an image and specify the submit button and input of title My purpose is when I click on submit button the code must check the inside of the input tag(title) and if it’s empty(I mean equal to “” ) the border of the input become red else become green

JavaScript

enter image description here

Advertisement

Answer

Try like this

JavaScript

Use UseEffect hook , when title was changed , it will be fire , and you can make a check is title empty or not , also not need use state callback for set check value.

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