0

As the title says, is this.props possible to be changed in the component itself whether manually or automatically

manual change example

this.props.someData = 'some value'

I don't know how to change this.props automatically, so I can't write example of automatical change.

wychoi
  • 37
  • 5
  • 1
    No you shouldn't change the props inside the component. Instead, include a callback method in the props from the parent component. – mousetail Oct 17 '22 at 08:41
  • Why do you want to change the props? – Thomas Oct 17 '22 at 09:14
  • @mousetail I don't want to change the props inside the component itself. But the props keeps changing and I don't know why and where. So I asked that question. – wychoi Oct 17 '22 at 23:53
  • @Thomas I don't want to change, But the props keep changing. – wychoi Oct 17 '22 at 23:55

2 Answers2

1

Like @mousetail suggested, it's best practise to add an updater callback to the props:

this.props.updateData(value);

Roy Schut
  • 136
  • 4
  • Thanks for the answer, but I want to know if the props can be changed whether manually or automatically inside the component itself. – wychoi Oct 17 '22 at 23:59
  • Sorry, I understand. Props are immutable, so you can't. Can we help you find the source of the flaky prop? – Roy Schut Oct 18 '22 at 07:16
  • Sorry, I can't show any source code. That is our company product. I still exactly don't know why `this.props` was changing, but I solved my problem. Thank you for speding time for me. – wychoi Oct 18 '22 at 07:56
  • Great! (You could always share a stripped down version of the code, just to showcase the situation) – Roy Schut Oct 18 '22 at 08:28
0

My problem was that this.props automatically changed when a function was executed.

In code level, there is no code to change this.props.

And problem was solved suddenly when I turned on the redux-devtools.

I'm guessing there's a problem somewhere inside the library, but I'm not sure.

If someone knows about this problem or similar problem, please let me know.

And I'm very thankful to all the people that tried to help me

wychoi
  • 37
  • 5
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 23 '22 at 16:51