react-native - 如何在 React Native 中使用访问令牌注销
问题描述
我正在尝试使用登录期间返回的访问令牌注销。
import React from 'react';
import { Text, Alert } from 'react-native';
import { Drawer,Container, Content, Header, Right, Button } from 'native-base';
import { FontAwesome } from '@expo/vector-icons';
export default class SideBar extends React.Component {
render() {
//console.log(this.props.usertoken);
return (
<Container>
<Header>
<Right>
<Button transparent>
<FontAwesome name="close" size={24} color="#FFFFFF" onPress={() => this.props.closeDrawer()} />
</Button>
</Right>
</Header>
<Content>
<Button transparent onPress={() => Alert.alert('Log Out Button pressed')}>
<Text style={{fontSize: 24}}>Log Out</Text>
</Button>
</Content>
</Container>
);
}
}
我已经通过“this.props.usertoken”检索了此页面中的访问令牌...任何人都可以通过将该访问令牌绑定到注销按钮来帮助我了解如何注销。
解决方案
使用 Context API 创建全局状态或使用 redux 全局存储用户数据并访问用户数据(如令牌和其他事物)来处理它。
查看更多关于全局状态的信息:
上下文 API https://www.smashingmagazine.com/2020/01/introduction-react-context-api/
React Redux https://react-redux.js.org/
使用 Async storage 或 redux persist 将数据存储到应用程序重启后访问的应用程序数据中。
推荐阅读
- c++ - 如何通过 C++ 中的链接器进行模拟测试
- scala - saveAsObjectFile 和持久化 apache spark 有什么区别?
- java - 无法从 cxf-codegen-plugin 插件生成肥皂信封
- go - 如何在golang中结合接口和结构?
- node.js - aws-sdk(节点)S3 NoSuchKey 错误,由 listObjectsV2 返回的键
- c++ - Qt creator -fno-elide-constructors 不工作
- javascript - 异步/等待不适用于反应 js(钩子)
- java - 为什么双参数化函数接受浮点数而不接受浮点数?
- java - 通过 moditect maven 插件在 Java 13 模块中添加 ResourceBundle 服务提供者指令
- spring - 不支持请求方法“POST”-spring boot