使用基于 GatsbyJs 构建的 react-player 解析项目中的错误

问题描述

我正在使用 react-player 制作一个响应式网络播放器应用程序,以使用回调道具 onProgress 获取有关 playTime 和所有这些内容统计信息。但是当我编写 useState 的代码时,它给出了一个解析错误,说 Unexpected Token,Expected ";" 我也是使用 GatsbyJs 的新手,所以如果错误是因为这个,我就不会知道。这是我的一段代码:-

const Lesson = () => {
  const [watchComplete,setWatchComplete] = useState{false}

  const handleWatchComplete = ({ played }) => {
    console.log(played)
  }

  return (
    <div>
      <ResponsivePlayer
        url="https://www.youtube.com/watch?v=ovJcsl7vyrk"
        onProgress={handleWatchComplete}
      />
    </div>
  )
}

export default Lesson

解决方法

您的 useState 声明中有一个拼写错误。

改变这个:

  const [watchComplete,setWatchComplete] = useState{false}

为此:

  const [watchComplete,setWatchComplete] = useState(false)