I have a small React project where the user can add notes to a Row, and then play MIDI audio of the notes that have been added (using react-abc / abcjs). The selected Notes should also animate in, using react-transition-group.
My problem is that only one of these features (MIDI / animation) will work at the same time, and which one works depends on a parent components key
property. The two keys are
key={rowIndex + rowNotation}
key={rowIndex}
// where `rowNotation` is the updated data of what the MIDI should play when every new card is added
/* If `key` = `rowIndex + rowNotation`, MIDI will play when green button is pushed, but
react-transition-group will not perform an animation when adding / removing notes
If `key` = `rowIndex`, react-transition-group will perform enter / exit
animations, but react-abc MIDI will NOT play
*/
I can understand why the animation would stop working - if the key updates with new data, and not just the index, the component will re-render, which means the animation cannot happen.
But I cannot understand why the MIDI would stop working properly when the key is just the index.
It took me quite a while to even figure out that the key was causing the MIDI to stop playing. I've tried moving the MIDI component to different locations with no results, and I'm pretty stumped.
I have created a (hopefully simple) working Sandbox of my issue with instructions to replicate: https://codesandbox.io/s/transition-group-x-abc-midi-bug-hunt-so-279pv?fontsize=14&hidenavigation=1&theme=dark
I have commented every main component with information, but the 2 most relevant components to my problem are:
Board.js
: where the key can be changed to demonstrate the issue
CardRow.js
: where the actual react-abc
/ Midi
and react-transition-group
components are located.