I want to render 4 divs (with class .col-4) in every row div in React JS.
This is what I've already tried:
return (
<Styles>
<div className="container add-page">
<input className="add-movie container" type="text" placeholder="Search for movies" value={query} onChange={onChange} />
</div>
{results.length > 0 && (
results.map((movie) => (
if(rows%4===0){
<div className="row">
<ResultCard movie={movie} key={movie.id} />
}
rows++;
if(rows%columns===0){
</div>}
))
)}
</Styles>
)
But, I'm getting an unexpected token error in the line where I am using if statement. I guess it's got something to do with the JSX syntax.
This is the what the ResultCard Component's return looks like:
return (
<React.Fragment>
<Styles>
{movie.poster_path ? (
<div className="col-4">
<img
src={`https://image.tmdb.org/t/p/w200/${movie.poster_path}`}
alt={`${movie.title} Poster`}
height="300"
width="200"
/>
<Button variant="success">Add to Watchlist</Button>
</div>
) : (
<div className="col-4">
<img
src={NotFound}
height="300"
width="200"
alt="Poster not found"
/>
</div>
)}
</Styles>
</React.Fragment>
);
Basically, I want to have a row div and render 4 ResultCard Components in that row div. Then, I want to create another row div for other 4 ResultCard Components and so on and so forth.
P.S: I know there are a few similar questions on this site, but in those questions, the OPs' code was structured in such a way that the answers to those questions solved their problems but are not working for me. That's why I'm asking this here.