question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

playing prop doesn’t react to changes between `undefined` & `false`

See original GitHub issue

Current Behavior

If I render a ReactPlayer with playing set to undefined for a youtube video, then start the video by clicking play within the element, and update playing to be false, then the video continues playing.

const [ playing, setPlaying ] = useState(undefined);
return (
  <div>
    <ReactPlayer
      url={url}
      playing={playing}
      controls
      width='100%'
      height='100%' />
    <button onClick={evt => setPlaying(false)}>Stop if playing</button>
  </div>
);

https://jsfiddle.net/mrcoles/ckrnm12w/12/

Expected Behavior

I would expect when the playing prop changes from undefined to false that the video would stop playing (if it currently is).

Steps to Reproduce

  1. Try this JSFiddle: https://jsfiddle.net/mrcoles/ckrnm12w/12/
  2. Play the video
  3. Press the “Set playing to false” button

Environment

Other Information

If instead I switch between playing = true or false it correctly starts or stops the video (see this jsfiddle).

I can imagine a number of reasons why this wouldn’t work as I’d expect, but the reason I was trying to do this was (1) I want to allow users to start the video themselves and using the play button provided by the embed seems like the most robust way to do that and (2) I want to automatically pause the video if a user scrolls or swipes it off the screen.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
afzaalahmadcommented, Nov 11, 2020

@mrcoles yes playing prop can go out of sync with native control enabled. But you can make them sync yourself, by registering onPlay and onPause events. Have a look at this fiddle: https://jsfiddle.net/suem30ox/4/

1reaction
mrcolescommented, Nov 12, 2020

@afzaalahmad thanks—I appreciate you going the extra mile here! I‘ll close the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How are boolean props used in React? - Stack Overflow
JSX has exactly two ways of passing true, <MyComponent prop /> and <MyComponent prop={true} /> and exactly one way of passing false <MyComponent ......
Read more >
How to Avoid the “Boolean Trap” When Designing React ...
But, the real answer is that there is no expected behavior and you should wrap the library within your code in such a...
Read more >
React Top-Level API
Unlike the shouldComponentUpdate() method on class components, the areEqual function returns true if the props are equal and false if the props are...
Read more >
How to Convert Object Props With Undefined Type to Optional ...
The ColumnConfig type is inferred from a runtime validation function. I can't change this type directly. Instead, I have to transform the returned...
Read more >
Dealing With Stale Props and States in React's Functional ...
I work with React a lot, and the overlap there is that they can sometimes be the cause of stale props and state....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found