hox icon indicating copy to clipboard operation
hox copied to clipboard

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

Open itenl opened this issue 3 years ago • 1 comments

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 avatar Dec 12 '21 13:12 itenl

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

itenl avatar Dec 12 '21 16:12 itenl