尝试使用最流行的"Slider carousel“包之一,但想不出如何在Gatsby + Contentful的静态站点设置中使用它。我正尝试在本地运行这段代码。
import React from 'react';
import { makeStyles } from '@material-ui/core/styles/';
import BackgroundImage from 'gatsby-background-image';
import 'react-responsive-carousel/lib/styles/carousel.min.css';
import { Carousel } from 'react-responsive-carousel';
import Img from 'gatsby-image';
const useStyles = makeStyles(theme => ({
heroImage: {
height: '80vh',
},
}));
const HeroCarousel = ({ data }) => {
const classes = useStyles();
return (
<Carousel>
<div>
<BackgroundImage
fluid={data.heroImage.fluid}
className={classes.heroImage}
/>
{/* <Img fluid={data.heroImage.fluid} className={classes.heroImage} /> */}
</div>
<div>
<BackgroundImage
fluid={data.heroImage.fluid}
className={classes.heroImage}
/>
{/* <Img fluid={data.heroImage.fluid} className={classes.heroImage} /> */}
</div>
</Carousel>
);
};
export default HeroCarousel;Contentful here的查询终结点以前工作过的父级:
...
const RootIndex = ({ data }) => {
const [author] = data.allContentfulPerson.edges;
const news = data.allContentfulBlogPost.edges;
return (
<>
<HeroCarousel showThumbs={false} data={author.node} /> *Here is the component*
{/* <HeroBanner data={author.node} /> */}
</>
);
};
export default RootIndex;
export const pageQuery = graphql`
...

发布于 2020-02-03 03:29:41
已修复。不妨把这个问题留在这里,因为这可能是服务器端渲染站点上的图像滑块的一个很好的设置,而且gatsby-image内置了一些强大的图像优化功能。
这个小补丁起作用了:
<Carousel showThumbs={false}>https://stackoverflow.com/questions/60027170
复制相似问题