难以将React Virtuoso虚拟化库集成到具有MUI组件的React项目中

发布于 2025-02-09 09:49:02 字数 2793 浏览 2 评论 0原文

我正在尝试集成react-virtuoso's virtuoso 进入我的打字稿Web应用程序的下拉菜单popper,以虚拟化可检查选项的列表。我尝试使用react-window的变量izeList,但在视觉上遇到了一些问题,我认为列表中的选项有一些问题,我认为,因为lib可能对列表项目遇到问题”(选项和选项)组标头的)高度计算。基本上,从react-window调整后,我的Virtuoso组件根本不会呈现。



我正在为AutoComplete的Popper使用自定义的“ ListBoxComponent” Prop,并且是通过:

  • 定义一个“列表框”组件,将DIV返回DIV,用转发的Ref Prop包装上下文提供商下面的演奏家
    • 其中itemData是react.reaeactNode的数组,itemContent是函数(索引:number,item,item:react.reaeactelement)=>项目,当演奏家仍然没有呈现时,请尝试使用其他道具/不放弃
    • 我还尝试将ItemContent设置为(索引:数字,数据:React.Reactelement [])=>数据[索引],以防我误解了功能签名。
<Virtuoso
          data={itemData}
          totalCount={ELE_PER_PAGE}
          initialTopMostItemIndex={0}
          overscan={150}
          itemContent={renderItem}
        />
  • 设置const listBoxComponent = react.forwardref&lt; htmldivelement&gtbox)

以下是自动完整的,

  • 我在react> react> window list list listbox box react> Wistbox Box
<Autocomplete
      disableCloseOnSelect
      disabled={props.status !== 'success'}
      fullWidth
      getOptionLabel={(option) => option.name}
      isOptionEqualToValue={getOptionSelected}
      groupBy={(option) => option.group || ''}
      id='lists'
      includeInputInList
      inputValue={input}
      limitTags={-1}
      ListboxComponent={
        ListboxComponent as React.ComponentType<
          React.HTMLAttributes<HTMLElement>
        >
      }
      multiple
      onClose={() => {
        setInput('')
        props.prune()
      }}
      onChange={onChange}
      onInputChange={(event, value, reason) => {
        if (reason !== 'reset') {
          setInput(value)
        }
      }}
      options={getOptions}
      renderGroup={renderGroup}
      renderInput={(params) => (
        <TextField
          {...params}
          error={props.status === 'error'}
          label={`Lists (${selectedCount})`}
          variant='standard'
        />
      )}
      renderOption={renderOption}
      renderTags={() => null}
      size='small'
      value={[props.options.option]}
    />


br>
有人是否有react-virtuoso可靠地工作?如果是这样,您通常如何探讨它的任何问题?也许是时候弄清楚是否可以使用VSCODE直接调试甚至在容器化的项目上直接调试反应(这比本地React ProJ更复杂,这可能只需要npm start)。

谢谢。

I'm trying to integrate react-virtuoso's Virtuoso into my TypeScript web app's MUI Autocomplete dropdown menu popper in order to virtualize a list of checkable options. I tried using react-window's VariableSizeList at first but was having some issues with options in the list visually overlapping, I think because that lib may have an issue with list items' (both options' and option group headers') height computations. Basically, after adapting from react-window, my Virtuoso component isn't rendering at all.

I'm using a custom "ListBoxComponent" prop for the Autocomplete's popper, and am doing so by:

  • Defining a "ListBox" component returning a div with a forwarded ref prop, which wraps a context provider, which wraps the below Virtuoso
    • Where itemData is an array of React.ReactNode, itemContent is the function (index: number, item: React.ReactElement) => item, and the other props were tried absent/not-absent when the Virtuoso still did not render
    • I also tried setting itemContent to (index: number, data: React.ReactElement[]) => data[index] in case I was misunderstanding the function signature.
<Virtuoso
          data={itemData}
          totalCount={ELE_PER_PAGE}
          initialTopMostItemIndex={0}
          overscan={150}
          itemContent={renderItem}
        />
  • Setting const ListboxComponent = React.forwardRef<HTMLDivElement>(Listbox)

Below is the Autocomplete

  • Whose props I haven't mentioned work fine in a react-window ListBox
<Autocomplete
      disableCloseOnSelect
      disabled={props.status !== 'success'}
      fullWidth
      getOptionLabel={(option) => option.name}
      isOptionEqualToValue={getOptionSelected}
      groupBy={(option) => option.group || ''}
      id='lists'
      includeInputInList
      inputValue={input}
      limitTags={-1}
      ListboxComponent={
        ListboxComponent as React.ComponentType<
          React.HTMLAttributes<HTMLElement>
        >
      }
      multiple
      onClose={() => {
        setInput('')
        props.prune()
      }}
      onChange={onChange}
      onInputChange={(event, value, reason) => {
        if (reason !== 'reset') {
          setInput(value)
        }
      }}
      options={getOptions}
      renderGroup={renderGroup}
      renderInput={(params) => (
        <TextField
          {...params}
          error={props.status === 'error'}
          label={`Lists (${selectedCount})`}
          variant='standard'
        />
      )}
      renderOption={renderOption}
      renderTags={() => null}
      size='small'
      value={[props.options.option]}
    />

Has anyone gotten react-virtuoso to reliably work? If so how do you typically peer into any issues with it? Perhaps it's time to figure out if one can use VSCode to directly debug React even on a containerized project (which is more complex to start than a local React proj, which might just need npm start).

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文