小编sot*_*tar的帖子

如何通过流类型定义引用类型?

我试图在react v16.4.0中通过flowtype定义ref的类型,
但是我无法解决它,所以请让我知道如何定义它。

这些是示例代码。
我想知道如何定义道具类型的引用。

父母

export default class ParentComponent extends React.Component<Props, State> {
  constructor(props: Props) {
    super(props);
    ....
    this.listRef = createRef();
  }

  render() {
    return (
      <ChildComponent
        listRef={this.listRef}
      />
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

儿童

type Props = {
  listRef: Ref<>, // how to define here?
};

const ChildComponent = (props: Props) => {
  <div>
    <ul ref={props.listRef}>
    ...
    </ul>
    ...
  </div>
}
Run Code Online (Sandbox Code Playgroud)

模块版本

"react": "^16.4.0",
"flow-bin": "^0.73.0",
Run Code Online (Sandbox Code Playgroud)

ref reactjs flowtype

4
推荐指数
1
解决办法
4797
查看次数

标签 统计

flowtype ×1

reactjs ×1

ref ×1