我正在尝试在下一个 js 中使用带有 react-visibility-sensor 的 react-odometer js。在这里我得到一个像图像一样的错误?我怎样才能摆脱这个错误,请专家帮忙。
这是我的代码https://codesandbox.io/s/summer-dream-ysi00
import { useState, useEffect } from "react";
import dynamic from "next/dynamic";
import "odometer/themes/odometer-theme-default.css";
const Odometer = dynamic(import("react-odometerjs"), {
ssr: false,
loading: () => 0
});
import VisibilitySensor from "react-visibility-sensor";
export default function IndexPage() {
const [odometerValue, setOdometerValue] = useState(0);
const [view, setView] = useState(false);
const onVisibilityChange = (isVisible) => {
if (isVisible) {
setView(true);
}
};
useEffect(() => {
setTimeout(() => {
setOdometerValue(500);
}, 10);
}, []);
return (
<VisibilitySensor onChange={onVisibilityChange} offset={8} delayedCall>
<Odometer
value={view ? odometerValue : 0}
format="(,ddd)"
theme="default"
/>
</VisibilitySensor>
);
}