This is something that has been asked but the solutions i found on here do not work for whatever reason. I have an array in my MongoDB and I am attempting to display them on my front end client. Like so: Genre: Action, Sci-Fi
Just calling it brings them in as a single text element. I was attempting to use the .map function but gives me error everytime.
Here is the component. With my attempt at the array.
import React from "react";
import Row from 'react-bootstrap/Row';
import Button from 'react-bootstrap/Button';
import { Link } from 'react-router-dom';
import './movie-view.scss';
export class MovieView extends React.Component {
render() {
const { movie, onBackClick } = this.props;
return (
<>
<Row>
<div>
<img src={movie.imageUrl} />
</div>
</Row>
<Row>
//This is the part not working
<div>
<span> Genre: </span>
{this.state.movies.map(movie => {
return ( <div key={movie.genre}>
<Link to={`/movies/${movie.genre}`}>{movie.genre}</Link>
</div>
)
})
}
</dl>
</Row>
<Row>
<span className="meta-text">Directed by: <Link to={`/movies/${movie.director}`}>{movie.director}</Link></span>
</Row>
<Row className="text-white">
<h1>{movie.Title}</h1>
<p className="movie-description">{movie.description}</p>
<div>
<Button className="lg" variant="primary" onClick={() => {onBackClick(null);}}>Back to list</Button>
</div>
</Row>
</>
);
}
}
export class MainView extends React.Component {
constructor() {
super();
this.state = {
movies: [],
selectedMovie: null,
};
}
}
I'm not sure if you need more context than that, if so let me know. Just to explain the first part better, just calling {movie.genre} works fine but the results are "ActionSci-Fi" with no separation. Appreciate the help!