I'm a beginner in React Js, and I'm using React Js with BootStrap 5.2.0
My product cards are not getting displayed in a row
I want to display 4 product cards in a row.
Adding Codes:
Home Page code:
<div className="container-fluid mb-2">
<Carousel />
<div className="mt-2">
<div className="row">
<div className="col-md-2">
<GetAllCategories />
</div>
<div className="col-md-10">
<div className="row row-cols-1 row-cols-md-4 g-4">
<div className="col">
{products.map((product) => {
return <ProductCard item={product} />;
})}
</div>
</div>
</div>
</div>
</div>
</div>
PRODUCT CARD CODE:
const ProductCard = (product) => {
return (
<div class="card border-color rounded-card card-hover product-card custom-bg">
<img
src={"http://localhost:8080/api/product/" + product.item.imageName}
class="card-img-top rounded mx-auto d-block m-2"
alt="img"
style={{
maxHeight: "270px",
maxWidth: "100%",
width: "auto",
}}
/>
<div class="card-body text-color">
<h5 class="card-title d-flex justify-content-between">
<div>
<b>{product.item.title}</b>
</div>
<CategoryNavigator
item={{
id: product.item.category.id,
title: product.item.category.title,
}}
/>
</h5>
<p className="card-text">
<b>{product.item.description}</b>
</p>
</div>
<div class="card-footer">
<div className="text-center text-color">
<p>
<span>
<h4>Price : ₹{product.item.price}</h4>
</span>
</p>
</div>
<div className="d-flex justify-content-between">
<Link
to={`/product/${product.item.id}/category/${product.item.category.id}`}
className="btn bg-color custom-bg-text"
>
Add to Cart
</Link>
<p class="text-color">
<b>
<i>Stock :</i> {product.item.quantity}
</b>
</p>
</div>
</div>
</div>
);
};
export default ProductCard;
From the past 4 days, I'm struggling to resolve this issue.
Please help me to fix this.
Thank You
You need to move <div className="col"> from home page to ProductCard as first element in return statement. Sample code at https://codesandbox.io/s/falling-thunder-swzukd
I have data from an API which is an array of objects, there is an array inside the objects which i am trying to output on my react component. instead of displaying an array, it displays a joined version of the items in the array
{rides && <div>{rides.map((ride)=>
(<div >
<div className="flex bg-[#111] text-white my-3"key={ride.id} >
<div className="card bg-[#111] m-4 rounded-xl">
<div className="flex">
<div className="imageBox">
<img className="rounded" src={ride.map_url} alt="" />
</div>
<div className="contentBox mx-3">
<p className="my-2">Ride id: {ride.id}</p>
<p className="my-2">Origin Station: {ride.origin_station_code}</p>
<p className="my-2">Origin Path: {ride.station_path}</p>
<p className="my-2">Date: {ride.date}</p>
<p className="my-2">Distance</p>
</div>
</div>
</div>
</div>
</div>
)
)}</div>}
this is the json data i am trying to display station_path as an array in the component
[{"id":515,"origin_station_code":15,"station_path":[28,31,43,57,63,76,86],"destination_station_code":90,"date":"02/06/2022 03:50 PM","map_url":"https://picsum.photos/200","state":"Delhi","city":"Delhi"},{"id":464,"origin_station_code":5,"station_path":[55,60,72,86],"destination_station_code":90,"date":"03/10/2022 07:53 PM","map_url":"https://picsum.photos/200","state":"Dadra and Nagar Haveli","city":"Silvassa"},{"id":941,"origin_station_code":18,"station_path":[46,58,60,79,86],"destination_station_code":99,"date":"04/03/2022 01:53 PM","map_url":"https://picsum.photos/200","state":"Chhattisgarh","city":"Durg"},{"id":197,"origin_station_code":9,"station_path":[67,71,80],"destination_station_code":95,"date":"02/04/2022 04:10 PM","map_url":"https://picsum.photos/200","state":"Telangana","city":"Adilabad"},{"id":792,"origin_station_code":14,"station_path":[53,64,79,88],"destination_station_code":90,"date":"03/03/2022 09:29 AM","map_url":"https://picsum.photos/200","state":"Meghalaya","city":"Shillong"},
You can use JSON.stringify(ride.station_path) to display array.
I'm trying to put useState hook values to a component via props.
As I understand typescript complains that I didn't specify setActive to boolean type. Am I right? If so, how can I do it?
const Card = () => {
const [activeModal, setActiveModal] = useState<boolean>(false)
return (
<>
<ApproveModal active={activeModal} setActive={setActiveModal} />
<div className="card">
<div className="card-wrapper">
<div className="card-header">
<div className="card-header-left">
<img src={token} alt="token" />
<div className="card-header-info-tag">
<h1>WETH-WBNB LP</h1>
<p>Auto-Compounding</p>
</div>
</div>
<div className="card-header-right">
<p>Pancake</p>
<img src={pancake} alt="pancake" />
</div>
</div>
<div className="card-info">
<div className="card-info-item">
<div className="card-info-item-title">Staked</div>
<div className="card-info-item-value">$482.22K</div>
<div className="card-info-item-description">39595 LPs</div>
</div>
<div className="card-info-item">
<div className="card-info-item-title">APY</div>
<div className="card-info-item-value">365%</div>
<div className="card-info-item-description">Daily: 2.00%</div>
</div>
<div className="card-info-item">
<div className="card-info-item-title">TVL</div>
<div className="card-info-item-value">$482.22K</div>
<div className="card-info-item-description">39595 LPs</div>
</div>
</div>
<div className="card-button" onClick={() => setActiveModal(!activeModal)}>Approve</div>
</div>
</div>
</>
)
}
"text to fix little text problem"
"text to fix little text problem"
"text to fix little text problem"
And ApproveModal
interface ApproveModalProps {
active: boolean;
setActive: boolean;
}
const ApproveModal = ({active, setActive}: ApproveModalProps) => {
return (
<div className="modal">
<div className="modal-content">
<div className="modal-header">
<img src={modalLogo} alt="modalLogo" />
<div className="modal-header-info">
<div className="modal-header-info-title">WETH-WBNB LP</div>
<div className="modal-header-info-description">Auto-Compounding</div>
</div>
<div className="modal-header-info-swap">#PancakeSwap</div>
<img src={closeIcon} alt="closeIcon" className="close-button" />
</div>
<div className="modal-actions">
<div className="modal-actions-buttons">
<div className="deposit">Deposit</div>
<div className="withdrow">Withdrow</div>
</div>
</div>
<div className="modal-balance">
<div className="modal-balance-header">
<div className="modal-balance-header-left">
<div className="balance">Balance</div>
<div className="link">Create LP</div>
</div>
<div className="modal-balance-header-right">
<img src={updateIcon} alt="updateIcon" />
<div className="value">0.0000</div>
<div className="value-description">($0.00)</div>
</div>
</div>
<div className="balance-input">
<input type="text" />
<div className="input-button">MAX</div>
</div>
</div>
<div className="modal-info">
<div className="modal-info-apy">
<div className="modal-info-apy-title">APY</div>
<div className="modal-info-item">
<div className="apy-value">365%</div>
<div className="apr-value">APR: Swap 70.9% + GROW 73.5%</div>
</div>
</div>
<div className="modal-info-contact">
<div className="modal-info-contact-title">Contact</div>
<div className="modal-info-item">
<div className="contact-link">View on BScScan</div>
<div className="contact-address">oxAD6bD158869a97219447cf63b090</div>
</div>
</div>
<div className="modal-button">Approve</div>
<h1>No deposit free. No withdraw free.</h1>
</div>
</div>
</div>
)
}
Here is the code
The problem lies in your Card component. The error is saying that the setActive prop expects to receive a boolean value, but you are providing it with a function.
It should be expecting a function. You’ll want to change the props types on your Card such that setActive is a function whose argument is a boolean.
interface CardProps {
setActive: (active: boolean) => void;
…
If you want to be able to use a prevState callback when calling setActive inside the Card component, then you can use the exact type of your setActiveModal function, which is this:
interface CardProps {
setActive: React.Dispatch<React.SetStateAction<boolean>>;
…
I'm using Bootstrap's grid system in my ReactJS project. Under a row, I have multiple columns (col-md-4) which I want to animate as they are added to or removed from the row as the component state changes. But Using CSSTransitionGroup immediately under a row to let the columns render as children leaves a span under the row and above the columns ruining the columns' left float.
<div className="row">
<ReactCSSTransitionGroup
transitionName={`fadeIn`}
transitionEnterTimeout={200}
transitionLeaveTimeout={200}>
{list.map(user => { return (
<div className="col-sm-6 col-md-8 col-lg-4" key={user.id}>
<div class="card">
</div>
</div>
)})}
</ReactCSSTransitionGroup>
</div>
YIELDS:
<div class="row">
<span>
<div className="col-sm-6 col-md-8 col-lg-4" key={user.id}>
<div class="card">
...
</div>
</div>
</span>
</div>
What is the correct approach to this?
Solved : just add className="row" in CSSTransitionGroup element
Sample code Here:
<CSSTransitionGroup
transitionName="item"
transitionEnterTimeout={500}
transitionLeaveTimeout={300}
className="row">
{myIndustries}
</CSSTransitionGroup>
I have a tree like structure in HTML, and starting from the root, I would like to access only the content of its direct children using CSS selectors. Note that I don't have control on the structure of the HTML, so I cannot change it.
An example will help a lot here. Consider the following HTML code:
<div class="node">
<div class="children">
<div class="node">
<div class="children">
<div class="node">
<div class="children">
</div>
<div class="content">
<p class="name">Quarter-Final 1</p>
</div>
</div>
</div>
<div class="content">
<p class="name">Semi-Final 1</p>
</div>
</div>
<div class="node">
<div class="children">
<div class="node">
<div class="children">
</div>
<div class="content">
<p class="name">Quarter-Final 2</p>
</div>
</div>
</div>
<div class="content">
<p class="name">Semi-Final 2</p>
</div>
</div>
</div>
<div class="content">
<p class="name">Final</p>
</div>
</div>
I would like to get only the names of Semi-Final 1 and Semi-Final 2. Ideally with one CSS selector. How can it be done?
Thanks
Something along these lines (works only with jQuery at the moment, will work in CSS4):
.node > .children > .node > .content > .name:not(.node > .children > .node > .children .content > .name)