Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to destructure props in react

const { firstName, lastName, city } = person;
Comment

array destructuring in react

a =["Ravi", "Ronak", "Tushar"]

const [f,...h]=a
console.log(f,{...h}) // Ravi { '0': 'Ronak', '1': 'Tushar' }
console.log(f,...h) // Ravi Ronak Tushar
console.log([f,...h]) // [ 'Ravi', 'Ronak', 'Tushar' ]
console.log(a.toString) // [Function: toString]
console.log(a.toString()) // Ravi,Ronak,Tushar
console.log((a.toString().split(",").reverse()).toString()) // Tushar,Ronak,Ravi
console.log((a.toString().split(",").reverse())) // [ 'Tushar', 'Ronak', 'Ravi' ]
Comment

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
Comment

js Destructuring in React

const [state, setState] = useState();

useEffect(() => {
  // do something
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to export a function in nodejs 
Javascript :: react pass variable from child to parent 
Javascript :: jest run specific test 
Javascript :: how to deploy nextjs app on netlify 
Javascript :: react styled functional component 
Javascript :: foreach loop js arrow functons 
Javascript :: api testing app with websocket 
Javascript :: next auth session callback 
Javascript :: javascript Strict Mode in Function 
Javascript :: js hover event 
Javascript :: multer express file upload 
Javascript :: nuxt 3 plugin 
Javascript :: get param is react 
Javascript :: mongodb find array which does not contain object 
Javascript :: sveltekit tailwind 
Javascript :: js default parameter 
Javascript :: JavaScript .clearRect 
Javascript :: json stands for 
Javascript :: javascript copy value to clipboard 
Javascript :: react-bootstrap example 
Javascript :: sort array by date in javascript 
Javascript :: find multiple javascript 
Javascript :: javascript converting an array into a map 
Javascript :: javascript change video poster 
Javascript :: http header express 
Javascript :: add days to date javascript dd/mm/yyyy in input date 
Javascript :: c# beautify json string 
Javascript :: jquery on change on multiple elements 
Javascript :: match 
Javascript :: window resize done 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =