繁体   English   中英

反应本机和redux中的hoc组件?

[英]hoc component in react native and redux?

我想在用户请求Api调用时显示微调Api并且我将每个组件传递给高阶组件以检查是否在请求,如果请求则显示微调框,否则不

但是在这里我得到错误提示说不能将类作为函数调用

//-------------Hoc Component

HOC=component=>class extends React.component{

  render(){
    (return <component {...props} {...state}/>)}
  }
}

export default connect(mapStateToProps)(HOC)

//----------login component

export default HOC(connect(mapStateToProps,{actions})(Login))

没有HOC,它可以正常工作,但HOC会出错。 请让我知道如何连接两个高阶组件的解决方案

试试这个代码

const HOC = WrappedComponent => {
  class abc extends Component {
    render () {
      return (
        <WrappedComponent {...this.props} {...this.state} />
      );
    }
  }

  const mapStateToProps = state => ({ state });

  const mapDispatchToProps = dispatch => bindActionCreaters({..actions}, dispatch);
  return connect(mapStateToProps, mapDispatchToProps)(abc);
}

export default compose(
  HOC,
  connect(mapStateToProps)
)(Login);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM