Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot assign to read only property 'props' of #<Object> in react native

Cannot assign to read only property 'props' of #

I checked #1654 with no success. Please have a look at the issue in more detail here-

Screenshot of error

Basically what I am doing is using a Navigator to move from index page to ApplistGridView page. I see the navigation is successful(from logs) but, even before I see the screen I face this issue.

And chrome debug messages-

Chrome Debug messages

Code is posted at Github Haven't found a solution. What am I doing wrong?

like image 987
bozzmob Avatar asked Nov 24 '15 18:11

bozzmob


2 Answers

You cannot push to props this.props.nav.push({id: 'Applist', index: 2}); since component properties are read-only, as the error states. Props can only be derived from a parent component, but cannot be modified.

EDIT: This article is a great starting point for people confused in this matter as I was a while ago:) https://reactjs.org/docs/thinking-in-react.html

like image 179
Thomas Avatar answered Nov 19 '22 12:11

Thomas


If this is happening to you not because of props but because of state, you may be trying to do an assignment like this:

this.state.nav = 'whatever';

Remember that assignments to state in React should be like:

this.setState({
  nav: 'whatever'
});
like image 7
CPHPython Avatar answered Nov 19 '22 11:11

CPHPython