Is there a way to use es6 shorthand when passing a props with the same name?
const [showNavMenu, setShowNavMenu] = useState(false)
So this:
<NavMenu showNavMenu={showNavMenu} setShowNavMenu={setShowNavMenu} />
Will became this:
<NavMenu {showNavMenu} {setShowNavMenu} />
Advantages of Destructuring:It makes developer's life easy, by assigning their own variables. Nested data is more complex, it takes time to access, but by the use of destructuring, we can access faster of nested data. It improves the sustainability, readability of code.
You can destructure the React props object within the render method inside a React class component. You can also destructure the React props object within a React functional component.
What Is 'State' in ReactJS? The state is a built-in React object that is used to contain data or information about the component. A component's state can change over time; whenever it changes, the component re-renders.
If you don't want to use an extra variable, you can do this:
<NavMenu {...{showNavMenu, setShowNavMenu}} />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With