Inconsistent redux state updates

The default red area in the

figure is rendered according to the array hostedLand , with an initial length of 1.

hostedLandlength2

statehostedLandlength

and the console does not output anything.
reducer:

import { addHostedLand } from "../actions"

const mapStateToProps = state = {
// 
}

const mapDispatchToProps = dispatch => {
    return {
        addHostedLand: () => dispatch(addHostedLand()),
        deleteLand: (...args) => dispatch(deleteLand(...args)),
    }
}
class HomeComponent extends Component {
    render(){
        const { hostedLand, addHostedLand } = this.props
        console.log(hostedLand)
        return (
            <div>
                {hostedLand.map(land => 
                    <OtherComponent {...this.props} key={land.id} id={land.id} />
                )}
                <button onClick={addHostedLand}></button>
            <div>
        )
    }
}

export default connect(mapStateToProps, mapDispatchToProps)(HomeComponent)

OtherCompoent:

...
render () {
    const {id, deleteLand } = this.props
    return () {
        .....
        <button onClick={() => deleteLand(id)}><button>
        .....
    }
}
...
Nov.04,2021

in reducer, the original array is returned when deleted, and the hostedLand object is not updated, but it is still the original object. It will not trigger the new array returned when re-render; is added, and the hostedLand object has changed, so re-render will be triggered.


state has changed, but UI has not changed, which means that without re-render; state, it happens to be an array, which is a reference type, and your delete reducer is not a pure function and does not return a new array, so it is most likely caused by shouldComponentUpdate.
so, start guessing:

  1. your component extends PureComponent, looks at the code and finds that it is not; and it does not write shouldComponentUpdate
  2. there is PureComponent or shouldComponentUpdate, in the parent component of your component. I can't see the code and cannot confirm
  3. The Provider in
  4. react-redux does not have an inject new store, to view the react-redux source code and finds the following code:
const hostedLand = (state = [initState], action) => {
  switch(action.type) {
    // 
    case 'ADD_HOSTEDLAND':
      return [
        ...state,
        {...initState,
          id: action.id
        }
      ]
    // 
    case 'DELETE_LAND':
      state.splice(action.id, 1)
      return {
          ...state
      }
    .....
  }
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9f33c-1a3b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9f33c-1a3b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?