Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Player won't rerender when remounting on a new page #165

Open
et-nat1995 opened this issue May 20, 2020 · 3 comments
Open

Player won't rerender when remounting on a new page #165

et-nat1995 opened this issue May 20, 2020 · 3 comments

Comments

@et-nat1995
Copy link

et-nat1995 commented May 20, 2020

I have two pages page A and page B

Page A uses a player with a config in jw player that auto plays when loaded on the screen.

Page B uses a player with a config in jw player that lets the user press play on the video.

When a user clicks on a link from page A to page B the package maintains the same config as page A in page B and vice versa.

Both players have different playerIds and I added a check to check if the page is mounted or unmounted. But that still doesn't make a difference.

Page A and B player setup:

const foo = (props) => {
  const classes = useStyles();

  const [isMounted, setIsMounted] = useState(false)
  useEffect(() => {
    setIsMounted(true)
    return () => {
      setIsMounted(false)
    }
  }, [])

  return (
        {
          isMounted ? <ReactJWPlayer playerId='unique_id' playerScript='https://cdn.jwplayer.com/libraries/some_player.js' playlist="https://cdn.jwplayer.com/feeds/some_id.json" /> : ''
        }
  )
}
@philmirez
Copy link

philmirez commented Jun 9, 2020

I was facing this same problem. It wasn't rerendering the video after changing the video id.

I stumbled across this closed issue, however it isn't in terms of hooks.

So, I updated it. 😁

const foo = (props) => {
  const [rerender, setRerender] = useState(true)

  useEffect(() => {
    setRerender(true)
  }, [props.videoId])

  useEffect(() => {
    if (rerender) {
      setRerender(false)
    }
  }, [rerender]


  return (
    <div>
      {!rerender && <ReactJWPlayer {...props} />}
    </div>
  )
}

@et-nat1995
Copy link
Author

@philmirez oh man i was pretty close. I'll give this solution a shot. Thank you

@jretamal
Copy link

If you have an example playlist List 1, List 2, List 3

When you click on playlist 1, the content of that playlist is displayed and it works, but if you load playlist 2, it still continues with playlist 1, for that you must assign a key to .

e.g:

<JWPlayer key={props.id}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants