Created
July 3, 2016 05:32
-
-
Save jafow/55444592676dc65d021c7565b05633ff to your computer and use it in GitHub Desktop.
React component that receives, extends, and transfers props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Row extends Component { | |
// this component receives props and extends it with color and effect. `super()` keyword permits us to use `this` | |
constructor(props) { | |
super(props) | |
this.color = 'blue' | |
this.effect = 'wow' | |
} | |
render () { | |
return ( | |
<div> | |
{ | |
this.props.letter.map((letter, index) => | |
<Box | |
// we can spread over props to pass down everything and explicitly declare the props we use. | |
{...this.props} | |
key={ index } | |
letter={letter} | |
// and here we add the new props created on line 4. | |
color={this.color} | |
// better for this specific example is to set new props directly on the component: | |
newProp={'this is a new prop value that can be accessed by child components at "props.newProp"'} | |
otherColor={'red'} | |
/> | |
) | |
} | |
</div> | |
) | |
} | |
} | |
export default Row | |
// here's a list of props available to this components children: | |
// newProp, otherColor, color, effect, plus all the props that were passed down to this component! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment