0

Here is my code

console.log(this.state.pins);
this.setState({ pins: [...this.state.pins, ...block] });
console.log(this.state.pins);

Here is what we see in the console...

enter image description here

enter image description here

More experementation... When I set my code to this.

this.setState({pins: this.state.pins.concat(block)});

enter image description here

So here I am using a map function.

{pins.map(pin => <PinnedBlock blockId={pin} /> )}

When I use the above map function on this array:

this.setState({ pins: [...this.state.pins, ...block] }); 

I get a <PinnedBlock blockId={pin} /> where pin is undefined.

When I use the above map function on this array:

this.setState({pins: this.state.pins.concat(block)});

I do not get an output corresponding to undefined.

Can someone explain help me understand what is happening here?

Community
  • 1
  • 1
Thomas Valadez
  • 1,697
  • 2
  • 22
  • 27

0 Answers0