I'm having an issue running a React component as I get a Syntax Error:
Failed to compile.
./app/javascript/RoastsJson/index.jsx Module build failed: SyntaxError: Unexpected token (6:10)
4 | class RoastsJson extends React.Component {
5 |
> 6 | render: function() {
| ^
7 | roasts = this.props.roasts.map( function(roast) {
8 | return (
9 | <tr key={roast.id}> @ ./app/javascript/packs/roastsjson.jsx 3:0-36 @ multi (webpack)-dev-server/client?http://localhost:3035 ./app/javascript/packs/roastsjson.jsx
just can't see why this would fail...my unrelated but I was having the same error when playing with files with const = url
with the error pointing to the u in url.
app/javascript/RoatsJson/index.jsx
import React from 'react'
import ReactDom from 'react-dom'
class RoastsJson extends React.Component {
render: function() {
roasts = this.props.roasts.map( function(roast) {
return (
<tr key={roast.id}>
<td>{roast.name}</td>
</tr>
);
console.log(roast);
});
return (
<div>
<h1>Roasts</h1>
<div id="roasts">
<table>
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
{roasts}
</tbody>
</table>
</div>
</div>
);
}
};
export default RoastsJson
I understand I could(should) remove function
, such as:
render() {
roasts = this.props.roasts.map( function(roast)
but this then throws the following in the conosle:
unreachable code after return statement
Context
I'm trying to pull a Rails 5.1 resource called roasts into this react component. in my roasts_controller.rb
:
def index
@roasts = Roast.all
render component: 'roatsjson', props: {roasts: @roasts}
end