0

how can I refactor loading 75 mp3 files as follows vs longhand?

const numberFiles = [];

for (let i = 0; i <= 75; i++) {
  const moduleFile = require(`./sounds/${i + 1}.mp3`);
  numberFiles.push(moduleFile);
}

run time keeps telling me

 [Error: TransformError App.js: App.js:Invalid call at line 27: require("./sounds/" + (i + 1) + ".mp3")]
Jose Manuel de Frutos
  • 1,040
  • 1
  • 7
  • 19
justdan0227
  • 1,374
  • 18
  • 48
  • Does this answer your question? [React Native - Image Require Module using Dynamic Names](https://stackoverflow.com/questions/30854232/react-native-image-require-module-using-dynamic-names) – Abe Jun 24 '23 at 04:01
  • no, I looked that over. I want to be able to dynamically load a number of required files without having to do it long hand. I don't know that **require** allows dynamic – justdan0227 Jun 26 '23 at 13:20
  • 1
    Exactly, it's not possible – Abe Jun 26 '23 at 14:50
  • Thanks. I’ll close and request of the RN feature list – justdan0227 Jun 27 '23 at 15:31

0 Answers0