1. HOC
Frontend people are familiar with HOC(High Order Component) or HOF(Higher Order Function). It can be thought as as an enhanced version of the original Component. Recently, I read an article about mixin pattern drawbacks in React (NOTE: mixing pattern now is obsolete, and HOC are recommended by Facebook React Team).
Personally, I love the way React Doc delivers its concepts, which is very natural and follow the way of regular thought process. Do have a look at this part: Higher-Order Components Explained. Thanks for the efforts from React Team.
2. connect()
from Redux
In React-Redux, we see connect()()
a lot, actually it is a HOC
. Let’s write one! Also note this.context
actually passed from <Provider>
created by Redux. And it use context
in React to pass it to its children.
[NOTE] The return of connect()
is: a wrapper function that takes your component and returns a wrapper component with the additional props it injects.
1 | export const connect = (mapStateToProps, mapDispatchToProps) => (WrappedComponent) => { |