Media Object Alignment Problem while using Reactstrap - reactjs

This is how I want my page to look
But, my issue is this is how it ends up looking like
I tried changing around the column size and tried to put two column classes tags col-5 and col-7 to the 2 media objects that hold the image and the text respectively as I would do in Bootstrap, but it doesn't seem to work.
My React Component is rendered according to the following code
render(){
const menu = this.state.dishes.map((dish) => {
return (
<Media>
<Media left middle>
<Media object src={dish.image} alt={dish.name} />
</Media>
<Media body className="ml-5">
<Media heading>{dish.name}</Media>
<p>{dish.description}</p>
</Media>
</Media>
);
} );
return (
<div className="container">
<div className="row">
<Media list>
{menu}
</Media>
</div>
</div>
);
}
}
Can someone help me see where I am going wrong?

This sounds stupid, but made two small tweaks and it worked. The issue was that my division of the component into two columns was not happening in the single component.
Tweak 1:
Removed the "row" div from the return container
Tweak 2: Added row div to the rendered JSX instead and added classes col-3 and col 9 to the image and the body
return (
<div key={dish.id} className="row text-center mt-5">
// Add a col-3 class to the image
<Media className ="col-3">
<Media object src={dish.image} alt={dish.name} />
</Media>
// Add a col-9 class to the body
<Media body className="col-9 ml-5">
<Media heading>{dish.name}</Media>
<p>{dish.description}</p>
</Media>
</div>
);
It now works

Check your version of bootstrap, I've rolled back from 5.0.2 (which was the latest for me) to the 4.0.0 and it actually worked.
What I've done:
Set the version of bootstrap in "package.json" to "^4.0.0"
deleted the "node_modules" folder
ran "npm install"
Also if you check reactstrap homepage, it says that it uses "Bootstrap 4 components". Maybe it's incompatible with bootstrap 5.

You are probably using bootstrap 5.
If you want to continue using BS5 for the course (that's what I did), you have to define Media according to the new rules of bootstrap 5. Here is the official explanation:
https://getbootstrap.com/docs/5.1/utilities/flex/#media-object
Here is the final code:
const menu = dishes.map((dish) => {
return (
<div key={dish.id} className="col-12 mt-5">
<div className='d-flex align-items-center'>
<div className="flex-shrink-0">
<img src={dish.image} alt={dish.name} />
</div>
<div className="flex-grow-1 ms-3">
<h3>{dish.name}</h3>
<p>{dish.description}</p>
</div>
</div>
</div>
);
});

You may have installed an incompatible bootstrap version. You can either change your code to work with your bootstrap version (following code is for version 5.2),
const menu = dishes.map((dish) => {
return (
<div key={dish.id} className="col-12 mt-5">
<div className='d-flex align-items-center'>
<div className="flex-shrink-0">
<img src={dish.image} alt={dish.name} />
</div>
<div className="flex-grow-1 ms-3">
<h3>{dish.name}</h3>
<p>{dish.description}</p>
</div>
</div>
</div>
);
});
Or you can change the bootstrap version by,
If you're using npm
npm uninstall bootstrap
npm install bootstrap#4.0.0
If you're using Yarn
yarn remove bootstrap
yarn add bootstrap#4.0.0

The reason why Media Object doesn't work using reactstrap is:
Bootstrap media object has been discontinued from version 5. However, you can still create a layout that contains left- or right-aligned media object like images or video alongside the textual content such as blog comments, Tweets, etc. using the flex and spacing utility classes.

Add className='d-flex' in first media tag
then add className='ms-5' in media body tag
if u are working in bootstrap v5 and react v6, it will surely help you

Related

How to stop Animate.css animation after one scroll in Rect.js?

I'm using react-on-screen and Animate.css to create slideInUp animation on scroll. But I want to the animation to show up when the page is loaded and the scroll-down happened. Now in my code, the animation happens every time I scroll up and down. How do I prevent that? Additional to that, if there is any way to do it without using Animate.css or react-on-screen I would love to learn it.
Here is the code that I track scrolling and Animate.css:
<>
<div className={`container mb-5 `}>
<h1 className='text-center my-5 blue-text'>SOME HEADER</h1>
<TrackVisibility partialVisibility>
{({ isVisible }) =>
<div className={`row animated-row my-element ${isVisible ? "animate__animated animate__slideInUp animate__repeat-1 my-element" :""}`} >
<Card />
<Card />
<Card />
<Card />
</div>
}
</TrackVisibility>
</div>
</>
I saw the "Usage with Javascript" codes on the Animate.css main page but I couldn't apply them to my React code.
Thanks.

How can I make custom button out of the DOM using react-multi-carousel?

dear.
Now I am building React app, and have a problem with react-multi-carousel.
enter image description here
Here are parts of my code. How can I solve this?
<div className="team_navigaation">
<div className="button"><i className="fa-solid fa-chevron-left"></i></div>
<div className="button"><i className="fa-solid fa-chevron-right"></i></div>
</div>
<Carousel
customLeftArrow={<CustomLeftArrow />}
customRightArrow={<CustomRightArrow />}
responsive={responsive}
>
{teams.map((team) =>
<Slide key={team.name} img={team.img} name={team.name} role={team.role}/>
)}
</Carousel>
If you want I will share the code and please help me.
Thanks.

React v18 causes error without code changes, JSX no longer accepted?

Since React 18 I have some errors when rendering the application and can't nest any elements as it seems.
For example, I have the following code in my application:
return (
<Card>
<div className={`flex flex-row justify-content-center align-items-center`}>
{props.icon}
<h2>{props.text}</h2>
</div>
<div className={"flex justify-content-center align-items-center"}>
<Button onClick={() => props.onButtonClick()} className={"w-2"} label={props.buttonText}/>
</div>
</Card>
);
This code worked fine up to React 18, now from 18 version I get the following error:
Likewise, element arrays can no longer be rendered, again, the following code worked fine in React17:
<DataTable metaKeySelection={false} selectionMode={"single"} onSelectionChange={e => {
setSelection(e.value)
}} selection={selection} stripedRows={true} showGridlines={true} size={"small"}
value={artifacts}>
{colModels}
</DataTable>
And now since React18 the following problem occurs:
It seems to me that with v18 React expects React Nodes everywhere and JSX as such is no longer accepted.
These errors disappear as soon as I enclose said elements with a React fragment, is this really the only way to solve this problem?
Thanks in advance!
Yes React 18 did make some changes I am not sure about your second issue but your first issue with card can be fixed like this...
Just add <> and </> React Fragment as the singlular child.
<Card>
<>
<div className={`flex flex-row justify-content-center align-items-center`}>
{props.icon}
<h2>{props.text}</h2>
</div>
<div className={"flex justify-content-center align-items-center"}>
<Button onClick={() => props.onButtonClick()} className={"w-2"} label={props.buttonText}/>
</div>
</>
</Card>

How to fix unexpected behavior of Next/Link when it is a child of a button?

I am experiencing some issues with next/link when I use it in my app.
I have a reusable component that renders a button. This component is used twice on the page with different urls each time.
When the page is in desktop view, the button works perfectly. I can navigate from one page to another. When I reduce the size of the screen to either tablet or mobile one redirects correctly and the other one does not respond as expected.
To work around the issue I have enclosed the area inside a link so the user can click outside the button area and still be directed to the page but it is not really the experience I want to offer to the user.
I never had this before. Can someone tell me how to fix this or why is it behaving this way, please? thanks.
const Banner = ({
purpose,
imageUrl,
title1,
title2,
desc1,
linkName,
buttonText,
}) => {
return (
<div className="row flex-lg-row-reverse align-items-center g-5 justify-content-center">
<div className=" col-10 col-sm-8 col-lg-6">
<Image
className="d-block img-fluid mx-lg-auto"
src={imageUrl}
width={700}
height={500}
alt="banner"
loader={myLoader}
/>
</div>
<Link href={linkName} passHref>
<div className="col-lg-4 p-3 text-center text-lg-start border-0">
<h1 className="display-6 fw-bold lh-1 mb-3">{purpose}</h1>
<p className="lead">
{title1}
<br /> {title2}
</p>
<p className="lead">{desc1}</p>
<button className="btn link btn-primary btn-xl w-100">
<Link href={linkName} passHref>
<a> {buttonText}</a>
</Link>
</button>
</div>
</Link>
</div>
);
};
export default function Home({ data }) {
const {
results: {
client: { secondhandListing },
},
} = data;
//console.log('index page results',secondhandListing);
return (
<>
<div
data-spy="scroll"
data-bs-target="main-nav"
data-offset="0"
className="scrollspy-example"
tabIndex="0"
>
<Services />
<div className="section d-flex justify-content-center my-5">
<h1 className="my-5" id="#scrollspyHeading2">
Properties
</h1>
</div>
<div className="container-fluid d-flex justify-content-xxl-between align-items-center flex-wrap flex-lg-nowrap">
<div className="section d-flex">
<Banner
purpose="Rent a Home"
title1="Rental Homes for"
title2="Everyone"
desc1="Explore Apartments, Villas, Homes"
desc2="and more"
buttonText="Explore Renting"
linkName="/search?operationType=rent"
imageUrl="https://bayut-production.s3.eu-central-1.amazonaws.com/image/145426814/33973352624c48628e41f2ec460faba4"
/>
</div>
<div className="section d-flex">
<Banner
purpose="Buy a Home"
title1="Find, Buy & Own"
title2="Your Dream Home"
desc1="Explore Apartments, Villas, Homes"
desc2="and more"
buttonText="Explore Buying"
linkName="/search?operationType=sale"
imageUrl="https://bayut-production.s3.eu-central-1.amazonaws.com/image/145426814/33973352624c48628e41f2ec460faba4"
/>
</div>
</div>
<Team />
<Contact />
</div>
</>
);
}
Run the new-link codemod to automatically upgrade previous versions of Next.js to the new <Link> usage:
npx #next/codemod new-link .
This will change <Link><a id="link">Home<a></Link> to <Link id="link">Home</Link>.
Alternatively, you can add the legacyBehavior prop <Link legacyBehavior><a id="link">Home<a></Link>.
<button> and <a> do not allow interactive content to be their content.
That said, you're passing invalid children to your <Link> component and to the <button> element:
<Link href={linkName} passHref>
<div className="col-lg-4 p-3 text-center text-lg-start border-0">
<h1 className="display-6 fw-bold lh-1 mb-3">{purpose}</h1>
<p className="lead">{title1}<br /> {title2}</p>
<p className="lead">{desc1}</p>
{/* Invalid child */}
<button className="btn link btn-primary btn-xl w-100">
{/* Invalid child */}
<Link href={linkName} passHref>
<a> {buttonText}</a>
</Link>
</button>
</div>
</Link>
That may be the reason of why your component is behaving oddly.
PS. Formatting your code helps by making it more readable. :). You can do that by setting ESLint and Prettier up.
You maybe need to add the legacyBehavior as props in the next/link component.
import Link from 'next/link'
function Legacy() {
return (
<Link href="/about" legacyBehavior>
<a>About Us</a>
</Link>
)
}
export default Legacy
docs: https://nextjs.org/docs/api-reference/next/link#if-the-child-is-a-tag

React local video does not load in production

I am trying to loop a very simple video contained in src/Assets/videos.
When I deploy a local server with npm start, the video performs as expected, however, when I publish to production the video does not load. I am using AWS Amplify CLI to publish the app.
I tried to:
1). View the app in a different browser (Firefox and Chrome).
2). Load the video from /public via an environment variable.
3). Load the video via the react-player module.
My initial code was home.js component rendered in app.js:
import heroVideo from '../../Assets/videos/heroVid.mp4';
//...
export default function HomePage() {
return (
<div id="hero" align="center" className="center">
<div>
<video muted autostart autoPlay loop >
<source src={heroVideo} type="video/mp4"/>
Your browser does not support the video tag.
</video>
</div>
<div style={{width: '90%'}}>
<div>
<img src={logo} style={{height: '200px', borderRadius: '100px'}} className={classes.blue} alt={`${props.brandName} Logo`}/>
<h4>A QC HOME BUYERS COMPANY</h4>
<h1>QC General Contractors</h1>
<h2 className="script">Let's build your future together</h2>
<NavLink to="/request-quote" className="simple-link"><Button variant="contained" color="secondary">Request a quote</Button></NavLink>
</div>
</div>
</div>
)
}
Then I tried to load from /public:
export default function HomePage() {
return (
<div id="hero" align="center" className="center">
<div>
<video src={process.env.PUBLIC_URL + 'Videos/heroVid.mp4} muted autostart autoPlay loop />
</div>
<div style={{width: '90%'}}>
<div>
<img src={logo} style={{height: '200px', borderRadius: '100px'}} className={classes.blue} alt={`${props.brandName} Logo`}/>
<h4>A QC HOME BUYERS COMPANY</h4>
<h1>QC General Contractors</h1>
<h2 className="script">Let's build your future together</h2>
<NavLink to="/request-quote" className="simple-link"><Button variant="contained" color="secondary">Request a quote</Button></NavLink>
</div>
</div>
</div>
)
}
Finally react-player:
import heroVideo from '../../Assets/videos/heroVid.mp4';
import ReactPlayer from 'react-player'
//...
export default function HomePage() {
return (
<div id="hero" align="center" className="center">
<div>
<ReactPlayer url={heroVideo} loop="true" volume="0" muted="true" playing="true" style={{height: "100%"}} />
</div>
<div style={{width: '90%'}}>
<div>
<img src={logo} style={{height: '200px', borderRadius: '100px'}} className={classes.blue} alt={`${props.brandName} Logo`}/>
<h4>A QC HOME BUYERS COMPANY</h4>
<h1>QC General Contractors</h1>
<h2 className="script">Let's build your future together</h2>
<NavLink to="/request-quote" className="simple-link"><Button variant="contained" color="secondary">Request a quote</Button></NavLink>
</div>
</div>
</div>
)
}
I am still relatively new to react and AWS Amplify - Is there something I am missing?
Thanks in advance for any guidance.
Have you modified your rewrite rules to add mp4 ?
</^[^.]+$|\.(?!(css|mp4|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>
I was having the same issue as well, the easiest solution I found was to create an S3 bucket on AWS and upload the video file there and grab the src from said video. You're also gonna have to add public read access for your bucket/object.
Did #jsc31994 recommendation :
Uploaded the video on a S3 bucket and then used ReactPlayer
<ReactPlayer
url='https://xxx.s3.us-east-2.amazonaws.com/xxx-background.mp4'
playing={true}
loop={true}
muted={true}
controls={false}
id="background_video"
/>

Resources