Parsing error, unexpected keyword this showing in webstorm

2

marker = (list, index) => {
  return (
    <Marker
      key={index}
      id={index}
      value={list}
      icon={{
        url:
          this.props.type === 'projects' || index === 'loc'
            ? icon
            : {
              this.props.types.map(type => {
                switch (type.id) {
                  case '1':
                    return pink;
                  case type.id === 2:
                    return pink;
                  default:
                    return pink;
                }
              }),
            }
      }}
    />
  );
}; 

answered question

Where is the error?

No-one can answer this problem as you have presented it. Please provide more information about context.

I think this is something related to undefined variable. Can you check all the variables have correact data or a default value

Please read this stackoverflow.com/help/how-to-ask. Then edit your post and format your code so that people can understand it.

1 Answer

4

You are trying to run code within curly brackets where JSX would typically go.

marker = (list, index) => {
  return (
    <Marker
      key={index}
      id={index}
      value={list}
      icon={{
        url:
          this.props.type === 'projects' || index === 'loc'
            ? icon
            : { // <-- remove this
              this.props.types.map(type => {
                switch (type.id) {
                  case '1':
                    return pink;
                  case type.id === 2:
                    return pink;
                  default:
                    return pink;
                }
              }),
            } // <-- and this
      }}
    />
  );
}; 

Correct code

marker = (list, index) => {
  return (
    <Marker
      key={index}
      id={index}
      value={list}
      icon={{
        url:
          this.props.type === 'projects' || index === 'loc'
            ? icon
            : this.props.types.map(type => {
                switch (type.id) {
                  case '1':
                    return pink;
                  case type.id === 2:
                    return pink;
                  default:
                    return pink;
                }
              }),
            
      }}
    />
  );
}; 

posted this

Have an answer?

JD

Please login first before posting an answer.