0

Rails can't render a basic react component I've just started building out due to a supposed syntax error in one of my components. Thus far I haven't been able to figure out why this syntax is incorrect.

Here is the error:

ActionView::Template::Error (SyntaxError: unknown: Unexpected token (11:11)
   9 |   render () {
  10 |     return (
> 11 |       {this.renderMeetings()}
                  ^
  12 |     );
  13 |   }
  14 | ):
1: <h1>Events</h1>
2: 
3: <%= react_component('SearchContainer', {}, {prerender: true}) %>
4: 
5: <form action="/search_event" accept-charset="UTF-8" method="get">
6:   <input type="search" name="search" placeholder="Search meetings"/>

And here is the suspect component:

class SearchResults extends React.Component {

  renderMeetings() {
   return this.props.meetings.map((meeting) => {
     return <SearchResultsPost meeting={meeting} />
   })
  }

  render () {
    return (
      {this.renderMeetings()}
    );
  }

}

Any help you can provide is much appreciated!

0

1 Answer 1

1

{} are required when you want to put some javascript code inside html element, since you are directly calling a function from return then {} are not required, if you use a div then you need to use {}, Write it like this:

render () {
    return (
      <div>{this.renderMeetings()}</div>
    );
}

or

render () {
    return (
       this.renderMeetings()
    );
 }
Sign up to request clarification or add additional context in comments.

1 Comment

Whoops! Thanks for your quick response!

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.