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 can I pass React props in audio player?

I created a component for an audio player and I’m trying make the src editable in different files <audio controls src={sourceFile}/>.
I tried to use react props but it isn’t working how can I fix this?

I am using Next.js

Component file:

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

    const AudioPlayer = (sourceFile) => {
      return (
     <div>
        <audio preload="metadata" controls src={sourceFile} />
      </div>
      );
    };
    
    export default AudioPlayer;

index.js

<AudioPlayer sourceFile="audio.mp3" />

>Solution :

You need to change your const function parameter so it knows its looking for props

const AudioPlayer = ({sourceFile}) => {...
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