1

How can I at the same time add this object into an array and change property popup to false to every other object (if there is any) in that same array?

 this.setState({
            map: {
                ...this.state.map,
                areas: this.state.map.areas.concat({
                    coords: [evt.nativeEvent.layerX, evt.nativeEvent.layerY, 15],
                    popup: true,
                })
            }
        });

1 Answer 1

1

You can't do this in the same time, but you could use Object.assign method and map in order to set the popup property to false and then just concat the new item.

areas: this.state.map.areas.map(item => Object.assign(item, {popup: false})).concat({
   coords: [evt.nativeEvent.layerX, evt.nativeEvent.layerY, 15],
   popup: true,
})
Sign up to request clarification or add additional context in comments.

1 Comment

That's it! Thank you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.