反应上下文临时,嵌套箭头功能与普通嵌套功能

时间:2019-03-26 09:17:32

标签: javascript reactjs arrow-functions

所以基本上我在这里有这个功能:

export function withContext () {
  return function withComponent (Component) {
    return function contextComponent (props) {
      return (
        <Consumer>
          {context => <Component {...props} {...context} />}
        </Consumer>
      )
    }
  }
}

当我包装我的组件的时候,这个没有问题

我想是为什么不尝试改用es8语法来使其更具可读性。所以我这样写我的函数:

export const withContext = () => Component => props => (
  <Consumer>
   {context => <Component {...props} {...context} />}
  </Consumer>
)

这根本不起作用。以下错误消息没有删除:

Unhandled Rejection (TypeError): Object(...) is not a function

我以这种方式使用两种功能:

export default withContext()(MyComponent)

我现在有点困惑,因为我认为嵌套箭头功能与上面的功能相同。

0 个答案:

没有答案
相关问题