I can't for the love of god find anything on this, or I just don't know exactly what to search for. I'm new to React and React Native and I need help with my RN project. What I'm trying to do is call a function auto_login()
in my component MainLogic
. The function looks as follows and is placed in the module.exports
:
auto_login: function(navigator){
if(GLOBALS.LOGGED_IN != true){
Keychain
.getGenericPassword()
.then(function(credentials){
fetch(GLOBALS.API_URL, {
method: "POST",
headers: {
'Accept': 'application/x-www-form-urlencoded',
'Content-Type': 'application/x-www-form-urlencoded',
},
body: "username=" + credentials.username + "&password=" + credentials.password,
})
.then((response) => response.json())
.then((response) => {
if(JSON.stringify(response.status).replace(new RegExp('"', 'g'), '').match("OK")){
GLOBALS.LOGGED_IN = true;
GLOBALS.USERNAME = credentials.username;
GLOBALS.PASSWORD = credentials.password;
navigator.push({
id: 'news'
});
}
})
.catch((e) => {
console.warn(e);
})
.done();
});
}
},
Right now I'm calling this function from
componentDidMount: function(){
MainLogic.auto_login(navigator);
},
before the render
function but I realise the navigator is out of context or something. I'd like some help to understand how I'd go about calling this function and binding the navigator
properly. I'm right now getting a warning:
TypeError: navigator.push is not a function. (in 'navigator.push({id:'news'})', 'navigator.push' is undefined.
Any help in understanding this is highly appreciated!
Edit: I'm using React.createClass.