Answers for "Destructuring props in react"

0

Destructuring props in react

const UserCard = ({ name, role, age, profilePic }) => {
  return (
    <div>
      <p>Name: {name}</p>
      <p>Role: {role}</p>
      <p>Age: {age}</p>
      <img src={profilePic} alt={name} />
    </div>
  )
}

function App() {
  const user = {
    name: "Ranjeet",
    role: "WordPress Developer",
    age: 27,
    profilePic: "image.jpg",
  }

  return (
    <div>
        <UserCard {...user} />
    </div>
  )
}

export default App
Posted by: Guest on April-10-2022
0

js Destructuring in React

const [state, setState] = useState();

useEffect(() => {
  // do something
});
Posted by: Guest on March-08-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language