Posts

Showing posts with the label ecmascript-6

React Native: require() with Dynamic String?

I have read several posts about issues that people are having with React Native and the require() function when trying to require a dynamic resource such as: Dynamic (fails) : urlName = "sampleData.json"; data = require('../' + urlName); vs. Static (succeeds) : data = require('../sampleData.json'); I have read on some threads that this is a bug in React Native and in others that this is a feature. Is there a new way to require a dynamic resource within a function? Related Posts (all fairly old in React time): Importing Text from local json file in React native React Native - Dynamically List/Require Files In Directory React Native - Image Require Module using Dynamic Names React Native: how to use require(path) with dynamic urls? As i have heard of, react's require() only uses static url not variables, that means that you have to do require('/path/file') , take a look at this issue on github and this one for more ...