【问题标题】:how do I write a ref to a component?如何将 ref 写入组件?
【发布时间】:2021-02-14 20:55:24
【问题描述】:

如何保存和写入 ScrollToFirstErrorHOC 组件的 Ref?

export function withScrollToFirstError(Component: t.form.Component): React.ComponentType {
  class ScrollToFirstErrorHOC extends PureComponent<OuterProps & PropsFromState> {
    constructor(props: PropsFromState) {
      super(props);
    }

    public render() {
      return <Component {...this.props} />;
    }
  }

【问题讨论】:

    标签: react-native components


    【解决方案1】:

    ScrollToFirstErrorHOC

    componentDidMount(){
       this.props.ref(this)
    }
    

    在父组件处

    <ScrollToFirstErrorHOC ref={_ref => this._scrollRef = _ref} />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-31
      • 2020-04-30
      • 2021-03-14
      • 2012-11-22
      • 2020-05-10
      • 1970-01-01
      相关资源
      最近更新 更多