Why did the react only use componentDidMount () to get the data? render executed it for me four times.

@connect(({ editnews,global, loading }) => ({
  global,
  editnews,
  loading: loading.models.editnews,
  timeLoading: loading.effects["editnews/getCollections"],
}))
componentDidMount() {
    message.warning(",",10)
    const { dispatch} = this.props;
    dispatch({
      type: "editnews/getCollections",
      payload: {}
    });
  }
render() {
    const {
      editnews: { data, data: { pagination }, collections },
      loading,
      timeLoading,
    } = this.props;
    console.log(pagination)

clipboard.png

Jun.23,2022

in a component state or props changes will execute the render method, probably because your other data has changed.
if you don't want to implement the render method, you can judge it in the shouldComponentUpdate method. return false can block render , which is also the solution recommended by react officially.


before looking for this problem, familiarize yourself with the lifecycle function of react. For example, you can take a look at this article ider" rel=" nofollow noreferrer "> http://kuaibao.qq.com/s/20190.... After reading it, print these two values in the lifecycle that receives state props changes, and you will find that they are changing all the time

.
Menu