0

I try to play video use ReactPlayer and set the playing from state and get some error.

Here my code:

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

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

This is the error:

0.chunk.js:31274 Warning: Failed prop type: Invalid prop playing of type string supplied to ReactPlayer, expected boolean.

Can someone explain to me why that is error, and how to fix it?

norbitrial
  • 14,716
  • 7
  • 32
  • 59

1 Answers1

0

As the error message states, it expects boolean but initially in your useState you pass "true" which considered as string.

You need to use boolean type instead of string as the following:

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

See from the official documentation for playing prop as:

playing: Set to true or false to pause or play the media

norbitrial
  • 14,716
  • 7
  • 32
  • 59