小编4YJ*_*4YJ的帖子

它的返回类型'Element | undefined' 不是有效的 JSX 元素。类型“未定义”不可分配给类型“Element |” 无效的'

使用 setInterval,我制作了 3 秒后更改屏幕的效果,使其看起来像移动应用程序。\n当我将其应用于 app.tsx 时,发生了错误。

\n

登陆/index.tsx

\n
import React, { useRef, useEffect, useState } from "react";\nimport * as S from "./style";\n\nconst Landing = () => {\n   const [sec, setSec] = useState<number>(3);\n   const time = useRef<number>(3);\n   const timerId = useRef<any>(null);\n\n   useEffect(() => {\n      timerId.current = setInterval(() => {\n         setSec(time.current % 60);\n         time.current -= 1;\n      }, 1000);\n\n      return () => clearTimeout(timerId.current);\n   }, []);\n\n   useEffect(() => {\n      if (time.current == 0) {\n         clearInterval(timerId.current);\n      }\n   }, [sec]);\n\n   if (time.current == 3) {\n …
Run Code Online (Sandbox Code Playgroud)

setinterval reactjs next.js

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

next.js ×1

reactjs ×1

setinterval ×1