Api 使用React本机链接和Redux-访问调度
我正在开发一个React本机应用程序,它连接到Instagram API。我正在经历将OAuth令牌交换为Instagram API所需的访问令牌的过程,最后一步是将访问令牌保存到数据库,我认为最好通过调度函数使用Redux 这是我的密码: 组成部分:Api 使用React本机链接和Redux-访问调度,api,react-native,redux,deep-linking,Api,React Native,Redux,Deep Linking,我正在开发一个React本机应用程序,它连接到Instagram API。我正在经历将OAuth令牌交换为Instagram API所需的访问令牌的过程,最后一步是将访问令牌保存到数据库,我认为最好通过调度函数使用Redux 这是我的密码: 组成部分: render() { return ( <View style={styles.container}> <Text>Connect to Instagram</Text
render() {
return (
<View style={styles.container}>
<Text>Connect to Instagram</Text>
<Button
onPress={this.props.authUserInstagram}
title={'Connect to Instagram'}
/>
</View>
);
}
我确实拿回了访问令牌,这很好。该应用程序是从SafariView打开的,因为我的节点服务器使用深度链接(链接库的作用是-React Native的一部分)将用户重定向回该应用程序。但我有两个问题:
从'react redux'导入{connect}
从“../Redux/LoginRedux”导入登录操作,{loggedInUser}
类型SignupScreenProps={
尝试注册:()=>无效,
}
类签名Upscreen扩展了React.Component{
道具:招牌广告
//您的组件逻辑
const handleUrl=事件=>{
//在这里删除侦听器,因为它有意义,而不是在组件中执行
Linking.removeEventListener('url',handleUrl);
var url=新url(event.url);
const code=url.searchParams.get('token');
const error=url.searchParams.get('error');
SafariView.disclose();
//这是您可以访问的方式。
this.props.attemptSignup();
};
render(){
//按钮视图
}
}
常量mapStateToProps=(状态)=>{
//在这里访问redux商店
返回{
达拉州
}
}
const mapDispatchToProps=(调度)=>{
返回{
尝试注册:(姓名、电子邮件、生日、性别、头像、密码)=>dispatch(LoginActions.signupRequest(姓名、电子邮件、生日、性别、头像、密码))
}
}
导出默认连接(mapStateToProps、mapDispatchToProps)(SignupScreen)
从'react redux'导入{connect}
从“../Redux/LoginRedux”导入登录操作,{loggedInUser}
类型SignupScreenProps={
尝试注册:()=>无效,
}
类签名Upscreen扩展了React.Component{
道具:招牌广告
//您的组件逻辑
const handleUrl=事件=>{
//在这里删除侦听器,因为它有意义,而不是在组件中执行
Linking.removeEventListener('url',handleUrl);
var url=新url(event.url);
const code=url.searchParams.get('token');
const error=url.searchParams.get('error');
SafariView.disclose();
//这是您可以访问的方式。
this.props.attemptSignup();
};
render(){
//按钮视图
}
}
常量mapStateToProps=(状态)=>{
//在这里访问redux商店
返回{
达拉州
}
}
const mapDispatchToProps=(调度)=>{
返回{
尝试注册:(姓名、电子邮件、生日、性别、头像、密码)=>dispatch(LoginActions.signupRequest(姓名、电子邮件、生日、性别、头像、密码))
}
}
导出默认连接(mapStateToProps、mapDispatchToProps)(SignupScreen)
export const authUserInstagram = () => {
return dispatch => {
return SocialApi.authUser()
.then(response => {
SafariView.show({
url: response.url,
fromBottom: true
});
Linking.addEventListener('url', handleUrl);
})
};
};
const handleUrl = event => {
//remove listener here as it makes sense rather than doing it in component
Linking.removeEventListener('url', handleUrl);
var url = new URL(event.url);
const code = url.searchParams.get('token');
const error = url.searchParams.get('error');
SafariView.dismiss();
//I wish to access dispatch here to save the token in the state
};