0

i have maybe stupid question. I m trying to save XML file which i load through xml2js with readfile function. I want to store file content string to global variable but i dont know how to get from promise then a value.

var myval;
var simpleStore = function(value){
   myval = value;
}
var myvariable = RNFS.readFile(APPLICATION_HISTORY_DIRECTORY, 'utf8').then(simpleStore);
Prasun
  • 4,943
  • 2
  • 21
  • 23
Vojtěch Prchal
  • 141
  • 1
  • 2
  • 11
  • Where you have defined this code, is it inside component where you have access to `state` or it is outside of component? – Prasun Apr 04 '18 at 14:09
  • Its outside of component.Before export default class and after imports.... – Vojtěch Prchal Apr 04 '18 at 14:10
  • What value you are getting in `myval`, the way you have handled promise it looks good, `myval` should have the required value. BTW do we want to make `myval` available to entire APP? – Prasun Apr 04 '18 at 14:15
  • I want to view content of file in component. myval is available in one file where i want to display it. I m getting undefined in myval. – Vojtěch Prchal Apr 05 '18 at 07:13
  • `myval` is `undefined` inside `simpleStore` function? Can you share a bit more code? – Prasun Apr 05 '18 at 18:31
  • No i mean outside but i cant use other functions inside so i cant work with text from file... – Vojtěch Prchal Apr 06 '18 at 05:20

0 Answers0