我想导出此代码并将其导入另一页。我该如何使用React做到这一点?因此,在我要进行幻灯片放映的页面上,我要做的就是插入“从“幻灯片放映”导入滑条;”?
幻灯片:
import React from "react";
import ReactDOM from "react-dom";
import { Gallery, GalleryImage } from "react-gesture-gallery";
const images = [
"https://images.unsplash.com/photo-1559666126-84f389727b9a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1356&q=80",
"https://images.unsplash.com/photo-1557389352-e721da78ad9f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80",
"https://images.unsplash.com/photo-1553969420-fb915228af51?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1049&q=80",
"https://images.unsplash.com/photo-1550596334-7bb40a71b6bc?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80",
"https://images.unsplash.com/photo-1550640964-4775934de4af?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80"
];
function App() {
const [index, setIndex] = React.useState(0);
React.useEffect(() => {
const timer = setInterval(() => {
if (index === 4) {
setIndex(0);
} else {
setIndex(prev => prev + 1);
}
}, 3000);
return () => clearInterval(timer);
}, [index]);
return (
<Gallery
style={{
background: "black",
height: "100vh",
width: "100vw"
}}
index={index}
onRequestChange={i => {
setIndex(i);
}}
>
{images.map(image => (
<GalleryImage objectFit="contain" key={image} src={image} />
))}
</Gallery>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
答案 0 :(得分:0)
您要在导出的代码底部需要一个导出语句。
例如
Export default App;
然后,您要导入到的代码顶部将需要导入语句。
例如
import App from "./app.js";
如果您想获得更好的答案,则可能需要编辑您的问题并将其清理干净。