N
N
Nikita Shchypylov2018-02-07 20:06:18
React
Nikita Shchypylov, 2018-02-07 20:06:18

Why does it issue Maximum update depth exceeded?

Hello.
I do not understand why there is always an update trigger in the component.
The code:

fetchBalanceUser() {
    let { users } = this.props; // это я получаю из редакса
    let login = this.state.user;
    Object.keys(users).map(element => {
      if (login === users[element].login) {
        this.props.fetchBalance(users[element].cash); // это я передаю в AC
      }
    });
  }

render() {
    this.fetchBalanceUser(); //вызываю
...

export const fetchBalance = val => {
  return {
    type: FETCH_BALANCE,
    payload: val
  };
};

import * as  actions from "../actions"

export function balanceReducer(state = 0, action) {
  switch (action.type) {
    case actions.FETCH_BALANCE:
      return action.payload;
    case actions.ADD_BALANCE:
      return state = state + action.payload;
    default:
      return state
  }
}

All this hangs the browser and swears:
5a7b31fe8891f583154175.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly Zharov, 2018-02-07
@Nikulio

actions should not be dispatched in the render method: a redraw occurs on the action, which throws an action, which causes a redraw, which throws the action

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question