Weird interaction 'react-virtualize'd working with 'react-sortable-hoc'

冷暖自知 提交于 2020-01-07 03:51:26

问题


https://codesandbox.io/s/qYEvQEl0

So I wrote a demo myself that didn't work compare to one sample that works, the only difference being one props for <List/>

rowHeight={({ index }) => 50}

rowHeight={50}

I use the latter way ofc. And it is not working. Why?


回答1:


Answer copied from the duplicate GitHub issue you filed ;)

This creates a new function prop each time you render:

rowHeight={({ index }) => 50}

The prop-change is sufficient to trigger a re-render of the child component even if no other properties changed. In the second example above, no props change at all and so List doesn't know it needs to re-render. (Check out the section on "pure components" in the docs for more info.)

In this case, you could pass a small attribute that changes each time sort order changes (eg an incremented counter) to let the component know to re-render. You could also call forceUpdate.



来源:https://stackoverflow.com/questions/44775957/weird-interaction-react-virtualized-working-with-react-sortable-hoc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!