Home > OS >  How to change props name in React components?
How to change props name in React components?

Time:07-13

Let's say I want the consumer of my component to give me this props:

<MyComponent
    firstProp='first value'
    secondProp='second value'
/>

And I have an internal state inside my component, called firstProp.

I know I can either change the name of the internal state, or change the prop name.

But this is a simple example. In reality in our codebase we have a huge dependency and hierarchy of components and it's not easy for us to change names.

I wonder if it's possible that I change the name of firstProp I recieve in my component to something else?

CodePudding user response:

in your consumer component :

const {firstProp:yourPrefferedName} = props
  • Related