I'm currently learning React and the idea of state and props is fairly new. At the moment I'm trying to create a SideNav component that renders some SideNavButton components. It's my first attempt at trying to pass props to child components and I keep getting this really unhelpful error that looks like this:
Syntax error: ./components/side-nav.js: Unexpected token, expected , (43:8)
41 | <SideNavButton button={button} />
42 | );
>43| });
.. | ^
44 | );
45 | }
46 |
I've honestly come to believe that this isn't even pointing at the problem. I'll post my code, and feel free to let me know if there is anything I could be doing better.
./index.js
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import SideNav from './components/side-nav';
const App = () => {
return (
<div>
<SideNav />
</div>
);
}
ReactDOM.render(<App />, document.getElementById('root'));
./components/side-nav.js
import React, { Component } from 'react';
import SideNavButton from './side-nav-button';
class SideNav extends Component {
constructor(props) {
super(props);
this.state = {
navButtons: [
{
label: "Profile",
icon: "fas fa-user",
location: "#!"
}, {
label: "Experience",
icon: "fas fa-book",
location: "#!"
}, {
label: "Education",
icon: "fas fa-university",
location: "#!"
}, {
label: "Technology",
icon: "fas fa-code",
location: "#!"
}, {
label: "Connect",
icon: "fas fa-share-alt",
location: "#!"
}
]
};
}
renderButtons() {
return(
this.state.navButtons.map(button => {
return(
<SideNavButton button={button} />
);
});
);
}
render(
return (
<ul className="side-nav">
{renderButtons();}
</ul>
);
);
}
export default SideNav;
./components/side-nav-button.js
import React from 'react';
const SideNavButton = ({button}) => {
return(
<li key={button.label}>
<a href={button.location}>
<i className={button.icon}></i>{button.label}
</a>
</li>
);
}
export default SideNavButton;
.jsxextension?.js.