【问题标题】:ReactPlayer want set playing but get warningReactPlayer 想要设置播放但收到警告
【发布时间】:2021-02-28 23:41:53
【问题描述】:

我尝试使用 ReactPlayer 播放视频并设置播放状态并出现错误。

这是我的代码:

function App() {
  const [playing, setPlaying] = useState("true");

  return(
  <ReactPlayer
        playing={playing}
        url={myvideo}
        muted={muted}
        onEnded={playNext}
      />
)}

这是错误:

0.chunk.js:31274 警告:道具类型失败:提供给 ReactPlayerstring 类型的无效道具 playing,应为 boolean

有人可以向我解释为什么这是错误,以及如何解决它吗?

【问题讨论】:

    标签: javascript reactjs react-hooks react-player


    【解决方案1】:

    正如错误消息所述,它需要boolean,但最初在您的useState 中传递"true",它被视为string

    您需要使用boolean 类型而不是string,如下所示:

    const [playing, setPlaying] = useState(true);
    

    playing prop的官方文档为:

    playing:设置为truefalse 以暂停或播放媒体

    【讨论】:

      猜你喜欢
      • 2021-02-28
      • 2021-11-29
      • 2021-03-01
      • 2016-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-29
      相关资源
      最近更新 更多