Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to pass data correctly into React / NextJS Video component?

I have a React based video player that is setup like this:

<ReactPlayer playing={true} controls={true} muted={true} loop={true} width="100" height="100" url='videos/330163_SF.mp4' poster="images/330163_C2B_Clean.png"></ReactPlayer>

This static URL is to be replaced with a dynamic URL coming from a data sheet:

const { videoID, videolink, id, thumb } = videoData

When put in a simple text bracket like this: {videolink}, the videolink is pulled and displayed correctly on the page:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

videos/general/100004_SF.mp4

However, inserting and passing the data to the video component in this way does not work

 <ReactPlayer playing={true} controls={true} muted={true} loop={true} width="100" height="100" url={'videolink'} poster="images/330163_C2B_Clean.png"> </ReactPlayer>

Where is my mistake?

>Solution :

You are passing a string as a prop not a variable when you inclose it in quotes

<ReactPlayer url={'videolink'} //This will always pass a string 
<ReactPlayer url={'videos/general/100004_SF.mp4'} //This would work for example
<ReactPlayer url={videolink} //This is the correct solution as eit t is now passing the variable. 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading