Skip to content
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

confusing props #5

Open
justinobney opened this issue Aug 5, 2016 · 1 comment
Open

confusing props #5

justinobney opened this issue Aug 5, 2016 · 1 comment

Comments

@justinobney
Copy link
Contributor

One of the things that confused me when I was getting into React was the difference between props and state. I think passing down a prop called state could potentially trip up others as well...

in: what-is-react.md

Using props, again, we will pass the selected state from the component down to the component by placing the property state={this.state.selected} on all of the components. Now that we know the state (i.e., this.props.state) and the current value (i.e., this.props.value) of the option we can verify if the state matches the value. If it does, we then know that this option should be selected. This is done by writing a simple if statement which adds a styled selected state (i.e., selectedStyle) to the JSX

if the state matches the value of the current option. Otherwise, we return a React element with unSelectedStyle styles.

state={this.state.selected} could be a little clearer as selected={this.state.selected}

@codylindley
Copy link
Collaborator

Yes. I need to re-do this. Thanks for bringing this to my attention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants