简体   繁体   English

针对表行操作的React redux最佳实践

[英]React redux best practice for table row action

I have a list of items. 我有一个项目清单。 I render a Table component with this list. 我用这个列表渲染一个Table组件。 I want to add a checkbox for each row. 我想为每一行添加一个复选框。 Do I have to use a separate component for the table row iteself in order to set the current row style by checking it without rendering the whole table? 我是否必须为表行iteself使用单独的组件,以便通过检查它而不渲染整个表来设置当前行样式? Becasase now when I change the item's 'selected' property, the whole table is rendering. 现在,当我更改项目的“选定”属性时,整个表格都会呈现。

Thanks :) 谢谢 :)

If your whole table re-render, you should clearly update your code to avoid that. 如果您的整个表重新渲染,您应该清楚地更新您的代码以避免这种情况。 Like you said, you can have a component for each row, so when a row update, only the row re-render. 就像你说的那样,每行可以有一个组件,所以当一行更新时,只有行重新渲染。 I'm strongly suggesting you to do this. 我强烈建议你这样做。 Be sure to include a key prop to each row to avoid performance leak. 务必在每行中包含一个关键支柱,以避免性能泄漏。 You can also use the shouldComponentUpdate method to avoid useless re-render. 您还可以使用shouldComponentUpdate方法来避免无用的重新渲染。 When passing your props down from the table component to the row component, make sure the objects your are passing are unique on don't change too often. 将道具从表组件向下传递到行组件时,请确保传递的对象是唯一的,不要经常更改。 If after all this, you realised you row will update and re-render often, you can try using react-virtualized , this library renders only the rows that are visible on the screen. 如果在这之后,您意识到行将更新并经常重新渲染,您可以尝试使用react-virtualized ,此库仅渲染屏幕上可见的行。 If you need more help, you can also share some code. 如果您需要更多帮助,还可以共享一些代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM