3

I have a function:

handleMarkerClick(targetMarker) {
    this.setState({
        markers: this.state.markers.map(marker => {
            if (marker === targetMarker) {
                return {
                    ...marker, //  error TS1136: Property assignment expected.

                    showInfo: true, // error TS1005: ',' expected.
                }; // error TS1135: Argument expression expected, error TS1005: ')' expected.
            }
            return marker; //  error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
        }), // Declaration or statement expected.
    });
}

and I see many errors:

  • Property assignment expected.
  • ',' expected.
  • Argument expression expected.
  • You may need an appropriate loader to handle this file type. | exports.__esModule = true; | exports["default"] = PopUpInfoWindowExample; | return marker;

But when I delete '...' near 'marker' my function wasn't work correct.

I do this:

    handleMarkerClick(targetMarker) {
    this.setState({
        markers: this.state.markers.map(marker => {
            if (marker === targetMarker) {
                return {
                    marker, // delete ...
                    showInfo: true,
                };
            }
            return marker;
        }),
    });
}

Why? What I can do to get right function?

7
  • Is marker a string? Commented Dec 26, 2016 at 1:23
  • marker is an element of array (markers) - it's react-google-maps tomchentw.github.io/react-google-maps/basics/pop-up-window Commented Dec 26, 2016 at 1:29
  • Is targetMarker an array? What is expected result of marker === targetMarker and ...marker? Commented Dec 26, 2016 at 1:35
  • Can you please show us the line numbers (and corresponding line in your post) for each error you're receiving? Commented Dec 26, 2016 at 1:36
  • targetMarker is a target marker (one) . marker === targetMarker - is a function to check clickable marker of markers array. Commented Dec 26, 2016 at 1:40

1 Answer 1

2

If marker is an object then instead of using the spread operator you can try using Object.assign(). Here's an example:

marker = Object.assign({}, marker);
Sign up to request clarification or add additional context in comments.

Comments

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.