gpt4 book ai didi

javascript - 下一个 js 应用程序无法运行 react 模块

转载 作者:行者123 更新时间:2023-12-04 17:19:39 25 4
gpt4 key购买 nike

我正在尝试通过此链接将整页滚动条 react 到我的下一个 js 应用程序中

https://github.com/ibrahim-ih/react-full-page-scroller

我已经使用 npx next-create-app 创建了一个应用程序并使用安装了模块

npm install --save react-full-page-scroller

并在index.js页面添加如下代码

import React from 'react'

import MyComponent from 'react-full-page-scroller'
import 'react-full-page-scroller/dist/index.css'

const App = () => {
const nav = [
{
id: 1,
title: 'title 1',
className: 'page-nav-button',
style: { width: '100%' }
},
{
id: 2,
title: 'title 2',
className: 'page-nav-button',
style: { width: '100%' }
},
{
id: 3,
title: 'title 3',
className: 'page-nav-button',
style: { width: '100%' }
}
]
const indicatorStyle = {
height: '8px',
width: '8px',
margin: '10px',
borderRadius: '4px',
backgroundColor: 'white',
transition: 'width 500ms ease'
}
const indicatorStyleActive = { width: '20px' }

return (
<MyComponent
pageNav={nav}
indicatorStyle={indicatorStyle}
indicatorStyleActive={indicatorStyleActive}
>
<div
className='bg-blue'
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center'
}}
>
<h1 className='page-number'>1</h1>
</div>
<div
className='bg-green'
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center'
}}
>
<h1 className='page-number'>2</h1>
</div>
<div
className='bg-red'
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center'
}}
>
<h1 className='page-number'>3</h1>
</div>
</MyComponent>
)
}

export default App

这显示了以下错误 enter image description here

注意我试过最简单的形式,就是在中间包裹 3 个 div它在我保存时第一次工作,但当我重新加载页面时,提到的错误再次出现。

最佳答案

看起来 react-full-page-scroller 与 SSR 不兼容,因此您只能在客户端动态导入它。

import MyComponent from 'react-full-page-scroller' 替换为以下行:

import dynamic from 'next/dynamic'

const MyComponent = dynamic(() => import('react-full-page-scroller'), {
ssr: false
})

关于javascript - 下一个 js 应用程序无法运行 react 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66986191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com