| Start |
|---|
| Introduction
Interesting things about
Basic example As you can see in the example, thanks to |
| Default props
Syntax ES5 ES6 ES7 The result of |
| PropTypes
Some primitive If you attach Syntax ES5 ES6 ES7 More complex props validation In the same way, Validating an object Validating on array of objects |
| Passing down props using spread operator Instead of Where each property needs to be passed as a single prop value you could use the spread operator Remember that the properties of the object that you pass in are copied onto the component's props. The order is important. Later attributes override previous ones. Another case is that you also can use spread operator to pass only parts of props to children components, then you can use destructuring syntax from props again. It's very useful when children components need lots of props but not want pass them one by one. |
| Props.children and component composition The "child" components of a component are available on a special prop, Which allows us to include an arbitrary number of sub-elements when using the component later: Props.children can also be manipulated by the component. Because props.children may or may not be an array (opens new window), React provides utility functions for them as React.Children (opens new window). Consider in the previous example if we had wanted to wrap each paragraph in its own Note the use of React.cloneElement to remove the props from the child Additionally, when adding elements in loops, be aware of how React reconciles children during a rerender (opens new window), and strongly consider including a globally unique |
| Detecting the type of Children components Sometimes it's really useful to know the type of child component when iterating through them. In order to iterate through the children components you can use React The child object exposes the RemarksNOTE: As of React 15.5 and up the PropTypes component lives in its own npm package, namely 'prop-types' and needs its own import statement when using PropTypes. See the official react documentation for the breaking change: https://facebook.github.io/react/blog/2017/04/07/react-v15.5.0.html (opens new window) |
Read Article
https://develop.horje.com/learn/1434/reference