2

I have an observe function in a react native app that is needed by the Parse react mixin:

var Parse = require('parse').Parse;
var ParseReact = require('parse-react');
var React = require('react-native');
var PollingPage = React.createClass({
  mixins: [ParseReact.Mixin],
  observe: function (props, state) {
    var inOutQuery = (new Parse.Query('IsOut'));
    return state.isLoading ? {inOuts: inOutQuery} : null;
  }, 
//etc


package.json:
  "dependencies": {
    "react-native": "^0.12.0"
  },
  "devDependencies": {
    "parse": "^1.6.7",
    "parse-react": "^0.5.0"
  }

however when this is run it goes off to look in local storage:

  getItem: function getItem(path) {
    return localStorage.getItem(path);
  },

Not to sure what is going on here.

I'm following this tutorial:

http://www.raywenderlich.com/106369/integrating-parse-react-native-ios#comments

The error: enter image description here

Nikos
  • 7,295
  • 7
  • 52
  • 88

1 Answers1

2

That because window.localStorage not exist in JavaScriptCore. localStorage is a part of Web APIs, but JavaScriptCore is just an javascript engine, not "web browser". You should use AsyncStorage instead of localStorage.

Please see this official doc for more information about RN js runtime.

[EDIT]

I think you used the wrong lib. From ParseReact:

As of version 1.6, the Parse JS SDK has a different build for React Native. If you're using Parse+React on React Native, you'll need to require the 'parse-react/react-native' package instead.

and you can also check \node_modules\parse\lib\react-native\, there are 3 difference storage implement: StorageController.browser.js, StorageController.default.js and StorageController.react-native.js. In StorageController.react-native.js, the getItem function look like that:

getItemAsync: function getItemAsync(path) {
  var p = new _ParsePromise2['default']();
  _reactNative.AsyncStorage.getItem(path, function (err, value) {
    if (err) {
      p.reject(err);
    } else {
      p.resolve(value);
    }
  });
  return p;
},
Fomahaut
  • 1,212
  • 1
  • 11
  • 18