Home > OS >  error onchange is not function render conditional
error onchange is not function render conditional

Time:06-08

I don't understand why functions are not recognized as such when they are inside a condition. The page retrieves the user's data, and when the user clicks on the edit button the inputs appear instead. Everything works, except I get in console that onChange is not a function. Is it possible to correct or must the code be modified? thank you for help

const DataUser = ()=>{
    const [lastname, setLastname] = useState("")
    const [updateInfoUser, setUpdateInfoUser] = useState(false)
   return(
    <>
      <div>
          <h3 >name:</h3>
           {   
             updateInfoUser=== true ? <input type="text" name="nom" onChange={(e) => (setLastname(e.target.value))} />
            : <div>
                 <p>{user.lastname}</p>
              </div>
           }
       </div>
    </>
)

}

CodePudding user response:

I don't get the error you claim you are getting. See example here: demo

Could you provide an example in codesandbox or something similar that produces your error message?

CodePudding user response:

Try using round brackets

Like this:

    const [lastname, setLastname] = useState("")
    const [updateInfoUser, setUpdateInfoUser] = useState(false)
   return(
    <>
      <div>
          <h3>name:</h3>
           {   
             updateInfoUser=== true ? (
             <input type="text" name="nom" onChange={(e) => (setLastname(e.target.value))} />
           ) : (
              <div>
                 <p>{user.lastname}</p>
              </div>
             )
           }
       </div>
    </>
)

} ```
  • Related