Skip to content

Instantly share code, notes, and snippets.

View estebanmunchjones2019's full-sized avatar

Esteban Munch Jones estebanmunchjones2019

View GitHub Profile
//Example of card image using <Image /> component
<div className="card" style={{width: "18rem"}}>
<Image
src="/assets/images/unsplash-1.jpeg"
// just put the original width and height of the original image, in order to provide the right aspect ratio
// Next.js will automatically reduce the size if the rendered image needs to be smaller.
width={2400}
height={1598}
layout="responsive"
<div>
<img />
</div>
//Or
<div>
<div>
<img />
</div>
//Example of background image using <Image> component
<div className="pt-2" style={{ position: 'relative', width: '100vw', height: '66.66vw'}}>
<Image
src="/assets/images/unsplash-1.jpeg"
layout="fill"
objectFit="cover"
/>
</div>
<Image src={path to your image} />
import Image from 'next/image'
//Example of a card image with <img>
<div className="card" style={{width: "18rem"}}>
<img src="/assets/images/unsplash-1.jpeg" class="card-img-top" alt="..." />
<div className="card-body">
<h5 className="card-title">Card title</h5>
<p className="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
//Background image example with <img>
<div className="pt-2">
<img src="/assets/images/unsplash-1.jpeg" style={{width: "100%", height: "auto"}}/>
</div>
// pages/api/subscription.js
export default function handler(req, res){
//some code here to save the email to a database
const email = req.body.email;
return res.status(200).json({text: `${email} successfully subscribed`});
}
// this code belongs to some dynamic route page, like /products/:id
export async function getStaticPaths() {
// some back end code here
return {
paths: [
{ params: { ... } }
],
fallback: true or false
};
export async function getServerSideProps(context) {
//some back end code here
return {
props: {}, // will be passed to the page component as props
}
}