From the course: React Hooks

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Reviewing Array and Object destructuring

Reviewing Array and Object destructuring - React.js Tutorial

From the course: React Hooks

Start my 1-month free trial

Reviewing Array and Object destructuring

- [Instructor] The most common place that object destructuring is used in React is inside of the component. So here we have a component that's rendering Hello World but we also can pass in to any one of these components an object called props. So that means that I can replace World with props.name. Then I can go back to our index file. I can pass in a name property. Let's say Alex. And then our component will render with the dynamic data. One way that we can shorten up our syntax here is we can destructure the props object. So because this is just literally an object, let's console.log it to check it out. Here's the object, here's the name. Let me get rid of the console message. And I can use destructuring to pop out just the name. So now if we hit Save, no changes but everything is working as expected. Destructuring is also used with arrays and it's used quite a bit with React hooks. So let's consider in our…

Contents