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

API 中是否可以提供 forwardRef 的支持 #84

Open
itenl opened this issue Dec 12, 2021 · 1 comment
Open

API 中是否可以提供 forwardRef 的支持 #84

itenl opened this issue Dec 12, 2021 · 1 comment

Comments

@itenl
Copy link

itenl commented Dec 12, 2021

hox的确灵活轻便,但尝试使用中对于class组件在高阶中无法获取ref, 是否可以为 withModel 函数扩展一个 forwardRef = true 的参数,与 react-redux connect 一致。

伪代码:

const BasicWrap = ChildComp => {
  class Basic extends React.Component {
    constructor(props) {
      super(props);
    }

    componentDidMount() {
      var name = ChildComp.name;
      console.log(name) // Wrapper
      var rf = this.comp;
       console.log(rf) // undefined
    }

    render() {
      return <ChildComp ref={comp => (this.comp = comp)} {...this.props} />;
    }
  }
  return Basic;
};
export default BasicWrap;


class Child extends React.Component {
  constructor(props) {
    super(props);
  }

  render() {
    // todo...
  }
}
const Model = withModel([useUserModel, useOrdersModel], ([user, orders]) => ({
  user,
  orders,
}))(Child);

export default BasicWrap(Model);

image

@itenl
Copy link
Author

itenl commented Dec 12, 2021

为 withModel 添加 Config.forwardRef,需求如上,本地 test && build 正常运行,望添加或这边PR,请审阅。

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