[英]react-redux prevent rerendering of list items when the state changes
I have a list item callled Row.我有一个名为 Row 的列表项。 The Row has three sections, I have stored the width of each sections in a state该行有三个部分,我已将每个部分的宽度存储在 state
rowWidth: [
{
id: 'name',
width: 200,
},
{
id: 'size',
width: 70,
},
{
id: 'status',
width: 150,
},
{
id: 'progress',
width: 200,
},
{
id: 'lasttry',
width: 200,
},
{
id: 'eta',
width: 50,
},
]
I change width of a single column by an external handle which updates the store.我通过更新存储的外部句柄更改单个列的宽度。
switch (actions.type) {
case consts.CHANGE_HEADER_WIDTH : return {
...state,
headerWidth: state.headerWidth.map((item) =>
item.id === actions.payload.id ? { ...item, width: actions.payload.neWidth } : item
),
}
break;
default : return state;
}
This is the row这是行
const headerWidth = useSelector((state) => state.ui.headerWidth)
const getWidth = useCallback((id) => {
const l = _.find(headerWidth, function (item) {
return item.id === id
})
return l.width
})
return(
<Row>
<Section1 style={{ width: getRow('name') }}/>
<Section2 style={{ width: getRow('size') }}/>
<Section3 style={{ width: getRow('status') }}/>
</Row>
)
My question is - how do I change the width of these divs without rerendering row我的问题是 - 如何在不重新渲染行的情况下更改这些 div 的宽度
Thank you all for the help.谢谢大家的帮助。 I understand that there has to be a rerender in order to view the state change.我知道必须重新渲染才能查看 state 更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.