Passing data to child component is not working in react - reactjs

***Menucomponent.js***
I have a on which onClick handler is working and sending dish detail to getDish function.which is passing data as a props to Cart component.
But it not working .Dishdetail is showing in menu component when i console.log it but won't show on cart component and undefined error.
<div className="row">
{this.props.dishes.map((dish, index) => {
return (
<Card
className="col-xl-2 col-lg-2 col-md-4 col-sm-6 m-3 text-white"
style={{ height: "400px", backgroundColor: "#1A0301" }}
>
<CardBody>
<CardTitle>{this.props.dishes[index].name}</CardTitle>
<CardSubtitle></CardSubtitle>
</CardBody>
<img
height="30%"
src={this.props.dishes[index].image}
alt={this.props.dishes[index].description}
/>
<button className="bg-dark text-white mt-4 " width="100">
<CardText>
Serve for - {this.props.dishes[index].serving}
</CardText>
</button>
<CardBody>
<CardSubtitle>
$$$ -{this.props.dishes[index].price}
</CardSubtitle>
</CardBody>
<button
className="text-white m-2 p-2 "
style={{ backgroundColor: "#FDA50F" }}
onClick={() => this.getDish(this.props.dishes[index])}
>
Order Now
</button>
<button
className="text-white m-2 p-2 "
style={{ backgroundColor: "#FDA50F" }}
>
<Link to="/cart" className="text-white">
Check cart
</Link>
</button>
</Card>
function which handle onclick event
getDishId(dishdetail)
{
return (
<React.Fragment>
<div className="container-fluid">{console.log(dishdetail.name)}</div>
<Cart dishdetail={this.props.dishdetail} />
</React.Fragment>
);
}
CartComponent.js
const Cart = (props) => {
return (
<React.Fragment>
<Card>
<CardImg width="100%" src="/assests/images/buffet.png" />
<CardBody>
<CardTitle>{console.log(props.dishdetail)}</CardTitle>
<CardText>{props.description}</CardText>
<Button>Button</Button>
</CardBody>
</Card>
</React.Fragment>
);
};

Related

Flex-grow not working Tailwind React h-screen

So i have an component with child inside the div component, it works fine at first but when the component keep increasing, instead of pushing the the footer the component overlapping the footer component causing an error like this:
as you can see it stack infront of the footer and overlapping it....
here is my try:
<div className="m-2 flex-grow">
<div className="flex flex-col md:flex-row md:justify-between">
<div className="flex">
<div
name=" grey window"
className="h-[130px] w-[130px] bg-[#d9d9d9]"
></div>
<div name="text" className="md :flex md:flex-col md:pt-0">
<div className="ml-2 text-left text-[#e44] md:text-xl text-base">
{props.props.sku_name}
</div>
<div className="md:text-l ml-2 text-left text-sm text-[#b4b4b4]">
{`Plant: ${props.props.plant}`}
</div>
<div className="md:text-l ml-2 text-left text-sm text-[#b4b4b4]">
{`SKU: ${props.props.sku}`}
</div>{" "}
<div className="md:text-l ml-2 text-left text-sm text-[#b4b4b4]">
{`Status: ${props.props.status}`}
</div>
<div className="md:text-l ml-2 text-left text-sm text-[#b4b4b4]">
{`Base Qty :${props.props.base_qty}, UOM: ${props.props.uom}`}
</div>
</div>
</div>
<div name="Buttons">
<div className="mt-2 flex gap-4 md:mt-0 md:flex-col">
<div className="rounded-md shadow">
<Button
variant="outlined"
size="medium"
color="error"
startIcon={<ContentCopyIcon />}
className="inline-flex items-center justify-center rounded-md border border-transparent w-32 bg-indigo-600 text-base font-medium text-white hover:bg-indigo-700 "
>
Copy
</Button>
</div>
<div className="rounded-md shadow">
<Button
variant="outlined"
size="medium"
startIcon={<ModeEditIcon />}
color="warning"
className="inline-flex items-center justify-center rounded-md border border-transparent w-32 bg-indigo-600 text-base font-medium text-white hover:bg-indigo-700"
>
Edit
</Button>
</div>
</div>
</div>
</div>
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>
{/* <div className="bg-white">
<Box sx={{ width: "100%", typography: "body1" }}>
<TabContext
TabIndicatorProps={{ style: { background: "#FF0000" } }}
value={value}
index={0}
classes={{ root: useStyles.tab }}
>
<Box sx={{ borderColor: "divider", p: 0 }}>
<TabList
index={0}
classes={{}}
onChange={handleChange}
variant="scrollable"
scrollButtons="auto"
aria-label="scrollable auto tabs example"
>
<Tab label="BOM" value="1" />
<Tab label="Calculation" value="2" />
</TabList>
</Box>
<TabPanel style={{ padding: 2 }} value="1">
Calculation
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>{" "}
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>
<div>
<p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
</div>
</TabPanel>
<TabPanel value="2" style={{ padding: 2 }}>
Calculation
</TabPanel>
</TabContext>
</Box>
</div> */}
</div>
and here is where i actually call the component to be used and display where there is data on it:
<div className=" m-2 p-2 mr-2 bg-white h-screen ">
<div className="text-left pl-2 pb-4 font-bold text-3xl">
<h2>Find Material</h2>
</div>
<div className="p-2 align-left">
<form
className="flex items-center"
onSubmit={(e) => {
e.preventDefault();
dataSKUList();
}}
>
<Autocomplete
isOptionEqualToValue={(option, value) =>
option.value === value.value
}
style={{ width: "100%", color: "#ffffff" }}
onChange={(event, newValue) => {
handleSetSKU(newValue);
}}
id="grouped-demo"
options={options.sort(
(a, b) => -b.firstLetter.localeCompare(a.firstLetter)
)}
groupBy={(option) => option.firstLetter}
getOptionLabel={(option) =>
option.sku_name + `, code:(${option.sku})`
}
sx={{ width: 300 }}
renderInput={(params) => {
params.inputProps.onKeyDown = handleKeyDown;
return <TextField {...params} label="Search by SKU" required />;
}}
renderGroup={(params) => (
<ul key={params.key}>
<li>
<GroupHeader>{params.group}</GroupHeader>
<GroupItems>{params.children}</GroupItems>
</li>
</ul>
)}
/>
<div>
<Button
type="submit"
color="success"
variant="contained"
style={{
marginLeft: 10,
width: "100%",
height: 54,
}}
startIcon={<ContentPasteSearchIcon />}
>
Search
</Button>
</div>
</form>
</div>
<div className="bg-white scrollbar-hide">
{show ? (
<div className="h-full">
<CardCalculation props={dataSpec} />
</div>
) : (
<></>
)}
</div>
</div>
can someone pointing out where it potentially be the error and any help on how to fix it?...
i think it will the h-screen that causing the problem....
Use flex-1 instead of flex-grow
Try Tailwind-play
I have added the footer, and now you dont see any overflow.

ReactJS Giving An Unexpected Warning: Each child in a list should have a unique "key" prop

It's a beautiful day but this thing is blocking my view:
I've tried everything (except asking a question ._.) and searched everywhere. But the expected result could not be obtained :'(
So, this is my code where I think the error is happening:
<div className="mt-3">
{data.activities?.map((act) => {
return <Chip className="mr-2 px-3" label={act} key={act.id} />;
})}
</div>{" "}
Well it's a part of my file packageCard.js but if you want the whole file here it is:
import Chip from "#material-ui/core/Chip";
import Clock from "./img/main_page_icons/clock.svg";
import Person from "./img/main_page_icons/person.svg";
import MapPin from "./img/main_page_icons/map-pin.svg";
import Package1 from "./img/main_page/package 1.png";
function PackageCard({ data }) {
console.log(data);
return (
<>
<div className="col-lg-4 col-md-6 col-sm-12 card-super-container">
<div className="card-container">
<div className="card-image-wrapper">
<div>
<div className="card-image-background">
<img
alt="package 1"
src={data.featuredImg}
style={{ borderRadius: "6px" }}
className="w-100 "
/>
</div>
</div>
</div>
<div className="card-details-container">
<span className="text-bold details-container-header">
{data.name}
</span>
<div>
<div className="card-details-text">
<div>{data.description}</div>
<div>
<h6 className="card-price">{`Price: ${data.price} USD`}</h6>
</div>
</div>
</div>
</div>
<div>
<div className="card-final-desc">
<div className="card-final-desc-item">
<span className="card-dot"></span>
<img alt="clock" src={Clock} className="mr-1" />
{` ${data.days}D / ${data.nights}N `}
</div>
<div className="card-final-desc-item">
<span className="card-dot"></span>
<img alt="clock" src={Person} className="mr-1" />
{` ${data.noOfPersons} Person `}
</div>
<div className="card-final-desc-item">
<span className="card-dot"></span>
<img alt="clock" src={MapPin} className="mr-1" />
{` ${data.destination} `}
</div>
</div>
</div>
<div className="card-btn-container">
<button className="btn zoki-btn">Book Now </button>
</div>
</div>
</div>
<div className="col-lg-4 mb-4">
<img
alt="package 1"
src={data.featuredImg}
style={{ height: 250 }}
className="w-100"
/>
<div
className="bg-white py-4 px-4 shadow-lg"
style={{ fontSize: 14, textAlign: "start" }}
>
<h6>{data.name}</h6>
<p>{data.description}</p>
<div className="d-flex justify-content-between w-100">
<h6 className="m-0">{`Price: ${data.price} USD`}</h6>
<h6 className="m-0" style={{ color: "#9C8E35", cursor: "pointer" }}>
Book Now
</h6>
</div>
/!*{" "}
<div className="mt-3">
{data.activities?.map((act) => {
return <Chip className="mr-2 px-3" label={act} key={act.id} />;
})}
</div>{" "}
*!/
</div>
<div
className="row shadow mx-3"
style={{ backgroundColor: "#9C8E35", fontSize: 12 }}
>
<div className="col-4 p-0 text-center">
<div
className="py-2 text-white d-flex w-100 justify-content-center"
style={{ borderRight: "1px solid white" }}
>
<img alt="clock" src={Clock} className="mr-1" />
<p className="mb-0">{` ${data.days} D / ${data.nights} N `}</p>
</div>
</div>
<div className="col-4 p-0">
<div
className="py-2 text-white d-flex w-100 justify-content-center"
style={{ borderRight: "1px solid white" }}
>
<img alt="clock" src={Person} className="mr-1" />
<p className="mb-0">{` ${data.noOfPersons} Person `}</p>
</div>
</div>
<div className="col-4 p-0">
<div className="py-2 text-white d-flex w-100 justify-content-center">
<img alt="clock" src={MapPin} className="mr-1" />
<p className="mb-0">{` ${data.destination} `}</p>
</div>
</div>
</div>
</div>
</>
);
}
export default PackageCard;
Packages.js Component
import { useState, useEffect } from "react";
import { getAvailablePackages } from "crud";
import PackageBg from "../../../assets/img/offers.jpg";
import Card from "./packageCard";
import CircularProgress from "#material-ui/core/CircularProgress";
import { useHistory } from "react-router-dom";
function Packages() {
const history = useHistory();
const [listPackages, setListPackages] = useState([]);
const [loading, setLoading] = useState(false);
useEffect(() => {
const params = {
search: { query: "" },
sort: "name",
page: 1,
pageSize: 3,
};
setLoading(true);
getAvailablePackages(params)
.then((res) => {
// console.log(res.data.data)
setListPackages(res.data.data.travelPackages);
setLoading(false);
})
.catch((error) => {
console.log(error.response.data);
console.log(error.response.status);
setLoading(false);
});
}, []);
let checkData = [
{
name: "ahmad",
description: "this is description",
price: 5,
days: 5,
nights: 9,
noOfPersons: 9,
destination: "England",
featuredImg:
"https://media.gettyimages.com/photos/castle-combe-in-the-fall-wiltshire-england-picture-id157006201?s=612x612",
},
{
name: "ali",
description: "this is description",
price: 5,
days: 5,
nights: 9,
noOfPersons: 9,
destination: "homeland",
featuredImg:
"https://images.unsplash.com/photo-1538332576228-eb5b4c4de6f5?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8ZmlubGFuZHxlbnwwfHwwfHw%3D&w=1000&q=80",
},
{
name: "ali",
description: "this is description",
price: 5,
days: 5,
nights: 9,
noOfPersons: 9,
destination: "finland",
featuredImg:
"https://images.unsplash.com/photo-1538332576228-eb5b4c4de6f5?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8ZmlubGFuZHxlbnwwfHwwfHw%3D&w=1000&q=80",
},
];
return (
<div
id="zoki-packages"
className="text-center py-5 my-5"
style={{
backgroundImage: `url(${PackageBg})`,
backgroundPosition: "center",
backgroundSize: "cover",
}}
>
<div className="container" style={{ color: "#344767" }}>
<h6 className="text-bold font-italic"> EXPLORE GREAT PLACES </h6>
<h1 className=""> Popular Packages </h1>
<div className="row justify-content-center align-content-center">
{checkData?.map((pkg) => {
return <Card data={pkg} key={pkg.id} />;
})}
{loading ? (
<CircularProgress className="my-4 ml-auto mr-auto" />
) : listPackages.length ? (
listPackages?.map((pkg) => {
return <Card data={pkg} key={pkg.id} />;
})
) : (
<h4 className="my-4 ml-auto mr-auto">
No Package Available at that time.
</h4>
)}
</div>
{listPackages.length ? (
<button
onClick={() => history.push("/search-packages")}
className="btn btn-dark px-4 p-2 rounded-pill my-4"
style={{ color: "#CFBD45", backgroundColor: "black", fontSize: 14 }}
>
<p className="mb-0"> VEIW ALL PACKAGES </p>
</button>
) : null}
</div>
</div>
);
}
export default Packages;
I will be very grateful if you find a solution. I appreciate any help you can provide <33
It seems that the act does not have a unique id, try using the index of the map.
<div className="mt-3">
{data.activities?.map((act, i) => (
<Chip className="mr-2 px-3" label={act} key={i} />
))}
</div>
if you use the act.id as the key,should make sure every id is unique cause
Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity
here is the official docs

How to click on link and redirects me to a new page in react

how to click on anchor tag in the card and redirects me to another page with more details of the current card
example
click on opens new tab with current (clicked) card details here is an api for item https://api.npoint.io/d275425a434e02acf2f7/News/0
snippets of code also a link that works https://codesandbox.io/s/sweet-spence-1tl4y5?file=/src/App.js
my api https://api.npoint.io/d275425a434e02acf2f7 for rendering all items in cards
filteredCat?.map((list) => {
if (list.showOnHomepage === "yes") {
const date = format(
new Date(list.publishedDate),
"EEE dd MMM yyyy"
);
const showCat = news.map((getid) => {
if (getid.id == list.categoryID) return getid.name;
});
// const rec = list.publishedDate.sort((date1, date2) => date1 - date2);
return (
<Card
className=" extraCard col-lg-3"
style={{ width: "" }}
id={list.categoryID}
>
<Card.Img
variant="top"
src={list.urlToImage}
alt="Image"
/>
<Card.Body>
<Card.Title className="textTitle">
{list.title}
</Card.Title>
<Card.Text></Card.Text>
<small className="text-muted d-flex">
<FaRegCalendarAlt
className="m-1"
style={{ color: "#0aceff" }}
/>
{date}
</small>
<div
style={{ color: "#0aceff" }}
className="d-flex justify-content-between"
>
<Button variant="" className={classes["btn-cat"]}>
{showCat}
</Button>
<div>
<FaRegHeart />
<FaLink />
</div>
</div>
</Card.Body>
</Card>
);
}
})
}
</div>
}
opens to a in new tab

How to solve problem with 2items with the same key?

I usually using uuid from react-uuid but this time I get all time an error even I try to combine it with unique item.id..
<Swiper
{...params}
>
{listMovie?.map((item, index) =>{
const time = new Date(item.release_date)
return(
<React.Fragment key={`${item.id + uuid()}`}>
<SwiperSlide >
<Grid item className="items">
<Card sx={{ maxWidth: "350" }}>
<div className="favorite">
<IconContext.Provider
value={{ color: 'red', size: '30px' }}
>
<div className="fav" onClick={() => FavHanlder(item, index)}>
{likes.includes(item.id) ? <MdFavorite/> : <MdFavoriteBorder/>}
</div>
</IconContext.Provider> </div>
<Link to={`/movie/${item.id}`}>
<CardMedia
component="img"
height="350"
image={`${apiConfig.w500Image(item.poster_path)}`}
// alt={item.Title}
/>
<CardContent>
</CardContent>
</Link>
</Card>
<div className="title">
<Typography variant="body2" color="white" >
{item.original_title}
</Typography>
<Typography variant="body2" color="white" >
({time?.getFullYear()})
</Typography>
<div style={{display: "flex", float: "left", paddingLeft: "10px", paddingRight: "10px"}}>
<ReactStars
count={10}
value={item.vote_average}
size={10}
isHalf={true}
emptyIcon={<i className="far fa-star"></i>}
halfIcon={<i className="fa fa-star-half-alt"></i>}
fullIcon={<i className="fa fa-star"></i>}
activeColor="#ffd700"
/><p style={{fontSize: "5px"}}>/{item.vote_count}votes</p></div>
</div>
</Grid>
</SwiperSlide>
</React.Fragment>
)})}
</Swiper>
I am a little bit confused, because this is an error of beginners.
full msg:
Warning: Encountered two children with the same key, .0. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.

React Owl Carousal responsive not working in smaller screens

My Owl carousel is not responsive on smaller or mobile screens. I want to find a way to solve this problem.
Following is the screenshots:
And here's the code. Thanks in advance
export default function HomeMovieSlider() {
return (
<div>
<OwlCarousel className='owl-theme'
loop center margin={1} autoplay ={true} dots={false} items={3} touchDrag={true} lazyLoad={true}
// responsive={"0:{items:1,},600:{items:3,},1000:{items:5,}"}
animateOut={'fadeOut'} animateIn={'flipInX'}>
{MOVIEBANNER.map((movieBannertop) => {
return (
<div >
{/* <h4>{movieBannerp.movieTitle}</h4> */}
{/* <img src={movieBannertop.bannerImage}/> */}
<Card style={{width: "250px"}}>
<Card.Img variant="top" src={movieBannertop.bannerImage} height="380" max-width= "100% !important"/>
<Card.Body>
<Card.Title as="h6" ><b>{movieBannertop.movieTitle}</b></Card.Title>
<Card.Subtitle className="mb-2 text-muted">{movieBannertop.genres}</Card.Subtitle>
<Link to="/MovieDetail"><small className="text-muted">More Details</small></Link>
</Card.Body>
<Card.Footer className="text-center">
<Button variant="danger" style={{backgroundColor: "#ff4444"}}><Link to="/movieBooking" style={{color: "#fff"}}>Book Now</Link></Button>
</Card.Footer>
</Card>
</div>
);
})}
</OwlCarousel>
<div className="col-xl-3 col-lg-3 col-md-3 col-sm-12 col-12"></div>
<div className="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
<div className="prs_animate_btn1 prs_upcom_main_wrapper prs_third_slider_btn">
<ul>
<li data-animation="animated fadeInUp"><span>MORE</span>
</li>
</ul>
</div>
</div>
<div className="col-xl-3 col-lg-3 col-md-3 col-sm-12 col-12"></div>
</div>
);
}
For making owl-carousel responsive, you should create a object named state with a responsive property and send it to the responsive prop of OwlCarousel.
export default function HomeMovieSlider() {
const state= {
responsive:{
0: {
items: 1,
},
450: {
items: 2,
},
600: {
items: 3,
},
1000: {
items: 4,
},
},
}
return (
<div>
<OwlCarousel
className="owl-theme"
loop
center
margin={1}
autoplay={true}
dots={false}
items={3}
touchDrag={true}
lazyLoad={true}
responsive={state.responsive}// add this line
animateOut={'fadeOut'}
animateIn={'flipInX'}
>
{MOVIEBANNER.map(movieBannertop => {
return (
<div>
{/* <h4>{movieBannerp.movieTitle}</h4> */}
{/* <img src={movieBannertop.bannerImage}/> */}
<Card style={{ width: '250px' }}>
<Card.Img
variant="top"
src={movieBannertop.bannerImage}
height="380"
max-width="100% !important"
/>
<Card.Body>
<Card.Title as="h6">
<b>{movieBannertop.movieTitle}</b>
</Card.Title>
<Card.Subtitle className="mb-2 text-muted">
{movieBannertop.genres}
</Card.Subtitle>
<Link to="/MovieDetail">
<small className="text-muted">More Details</small>
</Link>
</Card.Body>
<Card.Footer className="text-center">
<Button
variant="danger"
style={{ backgroundColor: '#ff4444' }}
>
<Link to="/movieBooking" style={{ color: '#fff' }}>
Book Now
</Link>
</Button>
</Card.Footer>
</Card>
</div>
);
})}
</OwlCarousel>
);
}
For other owl-carousels APIs see this link: https://github.com/laurenchen0631/react-owl-carousel

Resources