反应虚拟化中对 registerChild 的 CellMeasurer 支持

Fre*_*red 5 react-virtualized

在 CellMeasurer 中使用渲染道具 registerChild 作为 ref 似乎被 react-virtualized 忽略了:仍然收到警告 findDOMNode 已弃用。

那个评论:

https://github.com/bvaughn/react-virtualized/issues/1353#issuecomment-569814307 让我觉得这个修复是 4 个月前的,而 react-virtualized 的最新版本是 6 个月前发布的

虽然https://github.com/bvaughn/react-virtualized/blob/master/docs/CellMeasurer.md#using-registerchild已经在文档中提到过 ,但错误的是:

      {({registerChild}) => (
        <div
          style={{
            ...style,
            height: 35,
            whiteSpace: 'nowrap'
          }}
        >
          {content}
        </div>
      )}
Run Code Online (Sandbox Code Playgroud)

div 似乎缺少 ref={registerChild} !无论如何,无论是否在 div 上使用 ref={registerChild},仍然收到警告 findDOMNode 已弃用

小智 0

registerChild 的要点是为 cellMeasurer 提供对子组件的引用,从而无需调用 findDomNode。目前registerChild变量没有被使用,您需要添加设置子组件的ref到registerChild。

  {({registerChild}) => (
    <div
      ref={registerChild}
      style={{
        ...style,
        height: 35,
        whiteSpace: 'nowrap'
      }}
    >
      {content}
    </div>
  )}
Run Code Online (Sandbox Code Playgroud)