Sorry, no results found for "".
One of the major advantages of using DatoCMS instead of any other content management systems is its responsiveImage
query, which will return pre-computed image attributes that will help you setting up responsive images in your frontend without any additional manipulation.
To make it even easier to offer responsive, progressive images on your projects, we offer a package called react-datocms
that exposes an <Image />
component and pairs perfectly with the responsiveImage
query.
Our solution offers the same advantages of using Next Image component, with the added benefit of having beautiful low-quality image placeholders (LQIP) in base64 format embedded directly within the page, without any additional request to be made by the browser or server:
To take advantage of it, install the react-datocms
package:
Then, inside your page, feed content coming from a responsiveImage
query directly into the <Image />
component:
1import { request } from "../lib/datocms";2import { Image as DatoImage } from "react-datocms";3
4const HOMEPAGE_QUERY = `query HomePage($limit: IntType) {5 allBlogPosts(first: $limit) {6 id7 title8 coverImage {9 responsiveImage(imgixParams: { fit: crop, w: 300, h: 300, auto: format }) {10 sizes11 src12 width13 height14 alt15 title16 base6417 }18 }19 }20}`;21
22export async function getStaticProps() {23 const data = await request({24 query: HOMEPAGE_QUERY,25 variables: { limit: 10 }26 });27
28 return {29 props: {30 data31 }32 };33}34
35export default function Home({ data }) {36 return (37 <div>38 {data.allBlogPosts.map(blogPost => (39 <article key={blogPost.id}>40 <DatoImage data={blogPost.coverImage.responsiveImage} />41 <h6>{blogPost.title}</h6>42 </article>43 ))}44 </div>45 );46}