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 :: remove in javascript 
Javascript :: use two div id in jquery 
Javascript :: js indexof string 
Javascript :: js bind prototype arrow function 
Javascript :: form handling in react 
Javascript :: add style by classname javascript 
Javascript :: iterate object in js 
Javascript :: node query selector 
Javascript :: show json data in table using javascript 
Javascript :: how to define connection string in appsettings.json 
Javascript :: react date picker 
Javascript :: comparison operators in javascript 
Javascript :: inline style to change background color 
Javascript :: mui date picker 
Javascript :: if else function react native 
Javascript :: javascript callbacks anonymous function 
Javascript :: javascript reduce method stack overflow 
Javascript :: how to create new route in express 
Javascript :: for loop js Alternatives 
Javascript :: recordrtc 
Javascript :: how to set variable in discord.js 
Javascript :: what does connect do in redux 
Javascript :: apexcharts bar onclick index 
Javascript :: react native flatlist flex direction 
Javascript :: key codes javascript 
Javascript :: what is const in javascript 
Javascript :: javascript extend object 
Javascript :: node red json array 
Javascript :: apply css to shadow dom 
Javascript :: how to use $ in javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =