خرید بک لینک

Vote count: 0

I'm ruing into a problem, looking for help. I have a function called mapRanks. It gets called in componentWillMount and basically setState of elements using map through array of strings. It works fine with one array but I need to run it multiple times with multiple different arrays.

What happens is all the previous state becomes array[0] except the last one.

Please take a look at it:

export const mapRanks = (options, ranks, count, element) => {
  component = options.component;   // this component
  group = options.group;           // can be 'mapFirst', 'mapSecond', ...
  let col = count;
  let j = count;
  let k = count;

  const map = ranks.map((rank, i) => {
    if (i === col) {
      col = col + j--;
      if (j === 0) {
        j = k--;
      }
      retu [element(i, group, rank), <div key={ i } className="clearfix"></div>];
    }
    retu [element(i, group, rank)];
  });

  const newState = update(component.state, { maps: { [group]: { $set: map } } });
  component.setState(newState);

  setTimeout(() => { console.log(component.state.maps); }, 7000);
};

My state looks like this:

  constructor() {
    super();
    this.state = {
      maps: {
        mapFirst: [],
        mapSecond: [],
        mapThird: [],
        mapFourth: [],
      },
    };
  }

Also, I don't think it's related but I'm wondering... Do you see the setTimeout to console.log above? I had to use setTimeout because the state was retuing array[0] but with setTimeout, it retus the whole array of elements. Why is that?

asked 31 secs ago

برچسب: نویسنده: استخدام کار تاريخ: شنبه 12 تير 1395 ساعت: 10:18

صفحه بندی