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.

Hooks / React.useState cause flicker issue when used in onProgress

See original GitHub issue

Current Behavior

v2 - Using hooks along with state within onProgress callback creates a re-render loop. Player flickers endlessly.

Expected Behavior

Setting a separate piece of state that the player is not dependent on should not re render ReactPlayer

Steps to Reproduce

  1. Create a functional component to use ReactPlayer in
  2. Add a piece of state using hooks pattern ex. const [played, setPlayed] = React.useState(false);
  3. Create a handler function that updates state base on object passed ex.
const handleProgress = (playedObject) => {
    if (!seeking) {
  1. Use handler inside onProgress method on ReactPlayer ex. onProgress={handleProgress}

Example provided: Uncomment setPlayed inside handleProgress to see issue


Other Information

If we convert this to a class component or revert to v1 the issue is not present. Also state must be set to the passed value on the progress handler (using a static value to set state does not cause flicker)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

wouter-deencommented, Oct 22, 2021

For me, it ended up being cleaner to just have a one return statement with some conditional rendering inside. That also solved the problem of it flickering because it was inside a nested function’s return statement. I’m using react-player to play video files stored in a GCP storage bucket currently. I’m using the useState React hook for states like playing, started, progress etc.

cookpetecommented, Sep 26, 2022

@ferrero1987 Do you have a reproducible example of this happening? Does anyone?

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - useState counter flickers after clicking the button
However, clicking the button causes an immediate re-render and thus creates another timeout. This means there'll be 2 timeouts waiting, one from ...
Read more >
Avoid Flashes of Content in React with useLayoutEffect
[1:55] If we refresh the page, you can see that the green modal is flashing because it's being repositioned after the DOM paints....
Read more >
React Hooks cheat sheet: Best practices with examples
To prevent the user from seeing flickers of changes, you can use useLayoutEffect . The function passed to useLayoutEffect will be run before...
Read more >
Hooks API Reference - React
useReducer is usually preferable to useState when you have complex state logic that involves multiple sub-values or when the next state depends on...
Read more >
Useful React Hooks That You Can Use In Your Projects
React solves this problem with functional components and hooks, ... Setting states with the useState hook causes the corresponding component ...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found