我已开始使用Redux学习React Native,我正在使用Google和Facebook登录进行简单登录,我希望将其发送到AWS上的Parse后端。
我有以下Facebook按钮组件:
import { Button } from 'react-native';
import { connect } from 'react-redux';
import React, { Component } from 'react';
import { LoginManager } from 'react-native-fbsdk';
import { createUser } from '../actions';
class FacebookButton extends Component {
facebookButtonPressed(){
this.props.createUser("dummyemail@gmail.com","12345");
}
render() {
return (
<Button
onPress={this.facebookButtonPressed.bind(this)}
title="Sign In with Facebook"
color="#000000"
/>
);
}
}
export default connect(null,{ createUser })(FacebookButton);
我还没有完成任何Facebook集成,我只是想看看我是否可以创建一个解析用户。这是我正在使用的操作:
import Parse from 'parse/react-native';
export const createUser = (email, name) => {
return (dispatch) => {
var user = new Parse.User();
user.set("username", "my name");
user.set("password", "my pass");
user.set("name",name);
user.set("email", email);
// other fields can be set just like with Parse.Object
user.set("phone", "415-392-0202");
user.signUp(null, {
success: function(user) {
// Hooray! Let them use the app now.
console.log("User created");
},
error: function(user, error) {
// Show the error message somewhere and let the user try again.
alert("Error: " + error.code + " " + error.message);
}
});
}
};
当我在浏览器中运行调试器时,我能够看到createUser
被调用,当我们调用user.signUp
时,我收到以下错误:
undefined is not an object (evaluating 'reactNative.AsyncStorage.getItem')
当我阅读Parse Javascript文档并尝试以下内容时:
//Get your favorite AsyncStorage handler with import (ES6) or require
import { AsyncStorage } from 'react-native';
//Before using the SDK...
Parse.setAsyncStorage(AsyncStorage);
我在下面的代码中调用Parse.setAsyncStorage(AsyncStorage);
。
import ReduxThunk from 'redux-thunk';
import reducers from './src/reducers';
import Parse from 'parse/react-native';
import { Provider } from 'react-redux';
import Login from './src/screens/Login';
import React, { Component } from 'react';
import { AsyncStorage } from 'react-native';
import { createStore, applyMiddleware } from 'redux';
export default class App extends Component {
componentWillMount() {
Parse.initialize("MY KEY");
Parse.serverURL = 'MY URL';
Parse.setAsyncStorage(AsyncStorage);
}
render() {
const store = createStore(reducers, {}, applyMiddleware(ReduxThunk));
return (
<Provider store={store}>
<Login />
</Provider>
);
}
}
我收到reactNative2.default.setAsyncStorage is not a function
的错误。坦率地说,我试过Parse.setAsyncStorage(AsyncStorage);
希望解决上面提到的AsyncStorage问题。
那么在尝试创建Parse用户时,为什么我会收到有趣的AsyncStorage错误消息呢?
答案 0 :(得分:0)
我在这里留下答案,以防其他人遇到任何其他问题。问题是我使用的Parse
版本。我使用的是Parse版本1.6.14
。修复步骤:
package.json
文件,将Parse版本更新为1.11
以上的任何版本,对我1.11.1
工作。npm install
这应该解决上面提到的问题,请记住你必须实现:
//Get your favorite AsyncStorage handler with import (ES6) or require
import { AsyncStorage } from 'react-native';
//Before using the SDK...
Parse.setAsyncStorage(AsyncStorage);
根据文件。