Skip to content

Loading tracks dynamically with ReactJS #218

Answered by Micrufun
Micrufun asked this question in Q&A
Discussion options

You must be logged in to vote

More reliable approach

Declare playlist as a React state then:

  1. Employ useCallback to create the playlist.
  2. Employ useEffect to load the voices/tracks (upon voice/track update) and access the device microphone (upon playlist update).
Expand code
export default function DawTracks({ ee, voices, /* ... */ }) {

  // Playlist should be a `useState` to cause re-render.
  // Upon re-render due to playlist change, the device microphone is accessed reliably by a `useEffect`.
  const [playlist, setPlaylist] = useState({});

  //  To create the playlist:
  const container = useCallback(
    (node) => {
      if (node !== null && toneCtx !== null) {
        setPlaylist(WaveformPlaylist(
          {

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@Micrufun
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Micrufun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
0 participants