import "../../node_modules/react-image-gallery/styles/css/image-gallery.css";
import ImageGallery from "react-image-gallery";
import { useRef } from "react";
const images = [
{
original: "https://picsum.photos/id/1018/1000/600/",
thumbnail: "https://picsum.photos/id/1018/250/150/",
},
{
original: "https://picsum.photos/id/1015/1000/600/",
thumbnail: "https://picsum.photos/id/1015/250/150/",
},
{
original: "https://picsum.photos/id/1019/1000/600/",
thumbnail: "https://picsum.photos/id/1019/250/150/",
},
];
const Carousel = (props) => {
const imageGalleryRef = useRef(null);
const onClickHandler = () => {
imageGalleryRef.current.toggleFullscreen();
};
return (
<ImageGallery
items={images}
showThumbnails={true}
showFullscreenButton={true}
showPlayButton={false}
showBullets={true}
ref={imageGalleryRef}
onClick={onClickHandler}
/>
);
};
export default Carousel;
这返回imageGalleryRef.current.toggleFullscreen is not a function
,但我可以从控制台运行该函数,它的工作,我做错了什么?这是实现点击图像并全屏显示的最佳方法吗?
1条答案
按热度按时间sauutmhj1#
应该是
fullScreen
而不是toggleFullscreen
。根据功能文档:可以使用refs访问以下函数