Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can I use this package to extract atrributes of dynamic import react component #105

Open
boswellgao opened this issue Dec 25, 2020 · 0 comments

Comments

@boswellgao
Copy link

I have a HOC like this

const asyncComponent = (importComponent) => {
  class WrapComp extends React.Component{
      state = {
          component: null
      }
      componentDidMount(){
          importComponent().then(cmp => {
              this.setState({component: cmp.default});
          });
      }
      render(){
          const {forwardedRef, ...rest} = this.props
          C = this.state.component;
          return C ? <C ref={forwardedRef} {...rest} /> : null;
      }
  }

  return React.forwardRef((props, ref) => {
    return <WrapComp {...props} forwardedRef={ref} />;
  }); 
}

const component = asyncComponent(() => import('./another.js'))

as you can see, because the importComponent is dynamic imported, I cant use this package before the HOC return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant