ReactPlayer 想要设置播放但收到警告
ReactPlayer want set playing but get warning
我尝试使用 ReactPlayer 播放视频并设置播放状态并出现一些错误。
这是我的代码:
function App() {
const [playing, setPlaying] = useState("true");
return(
<ReactPlayer
playing={playing}
url={myvideo}
muted={muted}
onEnded={playNext}
/>
)}
这是错误:
0.chunk.js:31274 Warning: Failed prop type: Invalid prop playing
of type string
supplied to ReactPlayer
, expected boolean
.
有人可以向我解释为什么会出现错误,以及如何解决它吗?
如错误消息所述,它期望 boolean
但最初在您的 useState
中您传递了 "true"
,这被视为 string
。
您需要使用 boolean
类型而不是 string
,如下所示:
const [playing, setPlaying] = useState(true);
从playing
prop的官方文档中可以看到:
playing
: Set to true
or false
to pause or play the media
我尝试使用 ReactPlayer 播放视频并设置播放状态并出现一些错误。
这是我的代码:
function App() {
const [playing, setPlaying] = useState("true");
return(
<ReactPlayer
playing={playing}
url={myvideo}
muted={muted}
onEnded={playNext}
/>
)}
这是错误:
0.chunk.js:31274 Warning: Failed prop type: Invalid prop
playing
of typestring
supplied toReactPlayer
, expectedboolean
.
有人可以向我解释为什么会出现错误,以及如何解决它吗?
如错误消息所述,它期望 boolean
但最初在您的 useState
中您传递了 "true"
,这被视为 string
。
您需要使用 boolean
类型而不是 string
,如下所示:
const [playing, setPlaying] = useState(true);
从playing
prop的官方文档中可以看到:
playing
: Set totrue
orfalse
to pause or play the media