react-aplayer | : lollipop : A React wrapper component of APlayer | Audio Utils library
kandi X-RAY | react-aplayer Summary
kandi X-RAY | react-aplayer Summary
:lollipop: A React wrapper component of APlayer
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of react-aplayer
react-aplayer Key Features
react-aplayer Examples and Code Snippets
Community Discussions
Trending Discussions on react-aplayer
QUESTION
I am attempting to render playlist information for an Audio Player in React. The data is coming from a fetch call in the parent component (PostContent.js). The data being returned is an array of objects that looks like: [ {name: ‘track name’, artist: ‘artist name’, url: ’https://blahblah.wav', lrc: ‘string’, theme: ‘another string’ }, {…}, {…}, etc. }
I am not able to return the data in the render() method of the child component (AudioPlayer.js). When I console.log(this.props.audio) in the render(), my terminal prints three responses. The first is an empty array, and the next two are the correct data that I need (an array of objects).
How can I set the props on the ‘audio’ key in the ‘props’ object in the render() method of the AudioPlayer.js component?
I should mention that I am using the react-aplayer library, and I am able to make this work with hard-coded data, as in the example here (https://github.com/MoePlayer/react-aplayer), but I am trying to make a dynamic playlist component for a blog website. Any advice is greatly appreciated.
AudioPlayer.js (Child Component)
...ANSWER
Answered 2020-Apr-22 at 22:24Actually I think it doesnt work because you set this.props inside a props obejct, so maybe you need to do something like
QUESTION
I am trying to update the state with data received from a fetch request in the parent component. I am using the ‘react-aplayer’ library (https://github.com/MoePlayer/react-aplayer) as an audio player.
I am able to hard-code songs into the playlist as shown in ‘this.state.audio’ below. However, when trying to change this data to data received through props via the componentDidUpdate() method, I am not able to setState to the new data. When I console.log ‘this.state.audio’ to see the data, I get two messages: the first one with the hard-coded playlist info, and the next with my data received from the fetch request.
How do I update the state with the new data so that it replaces the hard-coded data?
Here is my component:
...ANSWER
Answered 2020-Apr-22 at 18:53After commenting back and forth it seems that this may be an issue with how React itself views your props and the order in which updates come in.
If you insist on updating your state from props then I recommend using the safer getDerivedStateFromProps
method which was introduced for issues like the one you're facing.
Updating state from props (when/how to use and why this method exists)
The second is to solely use props to render your playlist and pass in whatever initial playlist you'd like. ( I personally prefer this method )
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install react-aplayer
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page