Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change props name in React components?

Tags:

reactjs

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?

like image 534
Big boy Avatar asked Oct 20 '25 20:10

Big boy


1 Answers

in your consumer component :

const {firstProp:yourPrefferedName} = props
like image 52
abolfazl shamsollahi Avatar answered Oct 22 '25 14:10

abolfazl shamsollahi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!