Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

setting usestate to prop

function Avatar(props) {
  const [user, setUser] = React.useState({...props.user});

  React.useEffect(() => {
      setUser(props.user);
  }, [props.user])

  return user.avatar ? 
         (<img src={user.avatar}/>)
        : (<p>Loading...</p>);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #setting #usestate #prop
ADD COMMENT
Topic
Name
2+5 =