How can I reference my array of markers using setState?

Viewed 82

I have some old code that used to run but now I receive a warning. When fixing it using setState, I get a simple syntax error. Obviously I am misunderstanding something but not sure what. I have provided a snack example here that reproduces my error exactly.

calling setState causes error - Do not mutate state directly

I also included my original line below. It used to work fine.

From looking at a similar question I tried using just this.state.markers which gives the same error.

I appreciate any and all insight more than you know.

 ref={ref => this.state.markers[index] = ref}
1 Answers

typo in line 29, it should be

markers: [],
Related