Now I m building a webpage that shows a ranking of items. I m fetching datas with an external javascript file and using it by putting tag in nextjs page. The script uses the window variable, so I couldn t make it API and execuse it on the serverside.
Now my page is like below.
<div>
<Script src="/weeklyRanking.js" />
</div>
在小节中,我有各种项目,这是一个阵列,我希望在以下一页中使用。
{items.map((item)=>(
<div>{item}<div>
))}
我怎么能够把文字标签的变数上下页?
I tried below, weeklyRanking.js
let items = [item1,item2,item3];
window.items = items;
页: 1
import Script from next/script
const page = () => {
const [items, setItems] = useState([]);
}
useEffect(() => {
setItems(window.items)
}, [])
return (
<>
{items.map((item)=>(
<div key={item}>{item}</div>
))}
<Script src="/weeklyRanking.js" />
</>
)
}
export default page
The result is the items variable is undefined.