-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
props cannot change inside Component? #7
Comments
You can, technically, but it's a bad practice. It will even throw a React warning. These are guidelines we created to have a more maintainable code, not technical specs. |
Also, "Can change inside Component? No" and "Can change in child Components? Yes" seem paradoxical. Am I missing something? |
I think the correct phrasing would've been "Can change for child Components?" |
I have a question, in every react js tutorial/documentation it says that Props can't change, which I kinda understand, so, this means that the Value of a prop is the thing that can't change, right?, or it refers to the idea of adding more {key,value} to the 'props js plain object? maybe that is the thing that cannot change? i'm a little bit confused sometimes... I hope I could explain myself. thanks, cheers. |
someone was confused about the table too: here the question and answer in stackoveroflow: http://stackoverflow.com/questions/27991366/what-is-the-difference-between-state-and-props-in-react |
@meligatt the Since the props of one component can be another component's state, that can change freely. Think of components in terms of functions: var X = {y: 21};
function foobar(props) {
props.y = 42;
} Calling You can call |
Hello, I have a question about "Can get initial value from parent Component?" and "Can set initial value for child Components?". Props can be set by parent component, yes, but why state is marked as "Yes"? How can parent component set state of child component?
This code sets initial state based on props passed by parent component, but I would not say that in this code "initial state value is set by parent component." |
Hello ! The react documentation explains that props are read only. On the other hand after experimentation, the method that I use and that seems to me adapted is to implement a method in the component parent, this method will be responsible for modifying its state, then to pass this method to the component child. By calling this method in the child component, the state of the parent component will be changed. So the only source of truth remains the parent component. I hope this can help some! |
I ran into some similar issue. You might want to look into |
While this issue is quite old 😅, I wanted to provide a reference as some individuals might still have misconceptions. According to the React post(October 17, 2015), the React v0.14 - "setProps and replaceProps are now deprecated." |
I have one question on this table:
We can use 'setProps' in component. So I think props are able to change inside Component?
Thanks for any feedback!
The text was updated successfully, but these errors were encountered: