简体   繁体   English

react-redux 防止在 state 更改时重新呈现列表项

[英]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.

相关问题 React-redux 组件每次在商店中发生和未连接的 state 更改时都会重新渲染。 我该如何预防? - React-redux component rerenders every time when and unconnected state changes in the store . How do I prevent it? React,Redux,mapStateToProps,尽管状态发生了变化,但没有重新渲染 - React, Redux, mapStateToProps and no rerendering despite state changes react-redux - 连接的组件不会在状态更改时重新渲染 - react-redux - connected component not rerendering on state change 手动将存储传递给组件时,组件未重新呈现(react-redux) - Component not rerendering when passing store manually to components (react-redux) Redux State 更改但组件未重新渲染 - Redux State changes but component not rerendering 当 redux 状态改变时,React-Redux 在屏幕上渲染组件两次 - React-Redux rendering components twice on screen when redux state changes react-redux 中 redux 存储的非相关部分更新时组件重新渲染 - Component rerendering when non-related parts of redux store update in react-redux React-Redux状态管理:存储“选定”列表项的正确方法? - React-Redux state management: Proper way to store “selected” list items? 当状态发生变化时,防止react-redux重新呈现整个页面 - Preventing react-redux from re-rendering whole page when state changes React-redux:监听状态变化以触发动作 - React-redux : listening to state changes to trigger action
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM