I have this jsx
<div
className="row"
>
{data!== undefined && data.length !== 0 ? (
data.map((el) => (
<div className="col col-lg-2 col-md-6 g-3" key={el._id}>
<div className="card">
<div className="card-body">
<p className="card-text fw-bold fs-5">{el.name}</p>
</div>
</div>
</div>
))
) : (
<p>no data</p>
)}
</div>
Tried to resize my browser window and the cards didnt move, you can see the image. Why does this happen? How can I fix this?
2
Answers
The following code works. I guess you didn’t include Bootstrap correctly in your React project.
See the live demo.
package.json
index.tsx
App.tsx
Just as a side note, here is a suggestive cleaner code:
If the array is empty or undefined, it will always turn false so there’s no need to add the other conditions so this should work the same.
As for the problem you’re having, what version of React and Bootstrap do you have? Could you send a snippet of the App.jsx and your index file where you’re importing bootstrap?