Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Input tag value update after onChange but want to update it instantly

I am working on a input box where when useState detailsData is true (which is on a radio button) then setName will be my name otherwise it will be user input , but problem is if it is true then it shows nothing unless i click on input and try to type a word and after that it shows string ‘tejendra’.

 <input
                  type="text"
                  className="form_control"
                  value={name}
                  onChange={(e) => {
                    if (DetailsData === true) {
                      // setName(() => userDetailsData[1]?.name);
                      setName("tejendra");
                    } else {
                    setName(e.target.value);
                    }
                  }}
                />

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You should use useEffect to trigger a change in something else

useEffect(() => {
    if (DetailsData) {
        setName("tejendra");
    }
  }, [detailsData]);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading