diff --git a/react.md b/react.md index 4fe445a1b..deab66a4b 100644 --- a/react.md +++ b/react.md @@ -4,7 +4,7 @@ category: React layout: 2017/sheet ads: true tags: [Featured] -updated: 2017-08-26 +updated: 2017-08-31 weight: -10 --- @@ -70,23 +70,11 @@ render () { ··· } ``` +{: data-line="2"} Use states (`this.state`) to manage dynamic data. See: [States](https://facebook.github.io/react/docs/tutorial.html#reactive-state) -### Function components - -```jsx -function MyComponent ({ name }) { - return
- Hello {name} -
-} -``` - -Functional components have no state. Also, their `props` are passed as the first parameter to a function. -See: [Function and Class Components](https://facebook.github.io/react/docs/components-and-props.html#functional-and-class-components) - ### Nesting ```jsx @@ -106,6 +94,31 @@ class Info extends React.Component { Nest components to separate concerns. See: [Composing Components](https://facebook.github.io/react/docs/components-and-props.html#composing-components) +### Children + +```jsx + +

You have pending notifications

+
+``` +{: data-line="2"} + +```jsx +class AlertBox extends React.Component { + render () { + return
+ {this.props.children} +
+ } +} +``` +{: data-line="4"} + +Children are passed as the `children` property. + +Defaults +-------- + ### Setting default props ```jsx @@ -113,6 +126,7 @@ Hello.defaultProps = { color: 'blue' } ``` +{: data-line="1"} See: [defaultProps](https://facebook.github.io/react/docs/react-component.html#defaultprops) @@ -130,26 +144,35 @@ class Hello extends React.Component { Set the default state in the `constructor()`. -### Children +Other components +---------------- +{: .-three-column} + +### Function components ```jsx -class AlertBox extends React.Component { - render () { - return
- {this.props.children} -
- } +function MyComponent ({ name }) { + return
+ Hello {name} +
} ``` -{: data-line="4"} +{: data-line="1"} + +Functional components have no state. Also, their `props` are passed as the first parameter to a function. +See: [Function and Class Components](https://facebook.github.io/react/docs/components-and-props.html#functional-and-class-components) + +### Pure components ```jsx - -

You have pending notifications

-
+class MessageBox extends React.PureComponent { + ··· +} ``` +{: data-line="1"} -Children are passed as the `children` property. +Performance-optimized version of `React.Component`. Doesn't rerender if props/state hasn't changed. +See: [Pure components](https://facebook.github.io/react/docs/react-api.html#react.purecomponent) ### Component API