Keywords: State tree, Component Tree
Function that takes a component as a parameter and returns an augmented component. Can inspect and change passed props and hijack the render entirely
A Parent component accepts children as a function instead of a node.
<Parent> { param => () } </Parent> vs <Parent><Child /></Parent>
This allows the parent component to do some internal processing and inject props into a supplied child function.
this.props.children can be anything (opaque data structure), empty, single element, array of elements etc. React.Children API has a few utility functions: .only(this.props.children) -> only renders one element child .cound(this.props.children) -> show a count of how many children .map(this.props.children, func) -> map over children applying the passed in function .toArray(this.props.children) -> convert children of Node type to Array
Alternative to passing props down the component tree, effectively globally accessible props. Should be used sparingly but is useful for localisation and themeing.
old API:
in the root or grandparent component declare ChildContextTypes proptype object and a getChildContext Hook (producer):
App.childContextTypes = { locale: Proptypes.object }
getChildContext() {
return { locale: locales.en }
}
then in the grandchild component (consumer):
SomeChild.contextTypes = { locale: Proptypes.object }
in the render method:
render() {
const { locale } = this.context
}
however if any middle child implements ShouldComponentUpdate then the context breaks, to solve this pass the context props as references updating the object being referenced and using forceComponentUpdate Using higherorder comps we can abstract the old experimental API
custom function that sits inbetween the dispatcher and reducers, able to do some processing before an action reaches the reducer. the middleware curried function accepts a next param which if not called will stop the action propagating to the reducers.
convenience function that allow lookup and retrieval of data from the redux store the mapstatetoprops fuction should only map state to props and not have any logic in there (such as build new data from store data). selectors can be declared inside the reducer and used when connecting the store to the component, for reusability Selectors can be created when reducers have relationships, by creating selector the accepts in the entire state, it can take data from multiple reducers and combine them to make new data this is an alternative to importing two reducers when connecting a component for performance you should memoize your state, a common library to use is reselect
array and object operators ins es5 can be destructive, using the new spread operator (shallow copy) and map filter reduce methods we can operate on arrays and objects in an immutable fashion.
React recompose is a library that allows us to use functional components where you need class components. Class components extend React.Component which provides lifecycle hooks and internal state, as well as event handler methods. with recompose you can use helpers to compose functions and wrap your functional components.