score:2

Accepted answer
// Just set the state
const addName = () => {
  setUser({
     ...User,
     FirstName: FirstName
   })
}

// handle side effects here

useEffect(() => {
    // check is needed here, since it will be
    // called on component's first mount
    if(User.FirstName !== ''){
          console.log(User)
          props.addUserToFirebase(User)
    }
}, [User])

// This will be called whenever React detects a change in `User`

score:1

const nameOnChange = (event) => {
    setFirstName(event.target.value)
}

useEffect(()=>{
    if(FirstName !== ''){
         console.log(FirstName)
    }
}, [FirstName])

const addName = () => {
    setUser({
        ...User,
        FirstName: FirstName
    })
}

useEffect(()=>{
    if(User.FirstName !== '' && User.LastName !== ''){
          console.log(User)
          props.addUserToFirebase(User)
    }
}, [User])

Related Query

More Query from same tag