⭐️ If you like reactpatterns, give it a star on GitHub! ⭐️
Menu
React PatternsReact Patternsreactpatterns
HomeBlogGitHub
React PatternsReact Patternsreactpatterns
  • Home
  • Blog
  • GitHub
  • React Patterns
    • Introduction
    • Proxy component
    • Make the API call
    • Stateless function
    • Higher-Order function
    • Higher-Order component
    • Accessing a child component
    • JSX spread attributes
    • Render callback
    • Function as child component
    • Function as prop component
    • Component injection
    • Conditional rendering
      • If else
      • Ternary operation
      • Logical && operator
      • Switch case operator
      • Conditional rendering with enum
      • Multi-level conditional rendering
      • With higher order component
      • External templating component
    • Destructuring
      • What is destructuring?
      • Destructuring function argument
      • Nested destructuring
      • Destructuring rest/spread operator
    • Promises over callbacks
    • Container component (Stateful component)
    • State hoisting
    • Pure component avoid heavy re-render
  • React Anti-patterns
    • Props in initial state is an anti-pattern
    • shouldComponentUpdate avoid heavy re-renders
    • Indexes as a key is an anti-pattern
    • Spreading props on DOM elements is an anti-pattern

Nested Destructuring

Destructuring also applies to objects nested in objects.

For example#

Without destructuring:

function setIndexFromRoute(props) {
const modalList = props.modalList
const pathname = props.location.pathname
// ...
}

Destructuring the nested props object.

function setIndexFromRoute(props) {
const { modalList, location: { pathname } } = props
// ...
}
Previous
« Destructuring Function Argument
Next
Destructuring Rest/Spread Operator »
  • For example

Docs

  • Home

Community

  • Twitter
  • Facebook
  • LinkedIn

More

  • Blog
  • GitHub
Copyright © 2021 React Patterns Org.