简体   繁体   中英

hoc component in react native and redux?

i want to show spinner when user requesting Api call and i passed each component into higher order component to check is requesting or not if requesting show the spinner otherwise not

but here i getting error that says cannot call class as function

//-------------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))

Without HOC it is working fine but with HOC getting error. Please let me know the solution that how to connect two higher order component

Try this code

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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