我正在尝试使用登录期间返回的访问令牌注销。
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”检索到此页面中的访问令牌...谁能帮助我通过将该访问令牌绑定到注销按钮来注销。
答案 0 :(得分:0)
使用 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 将数据存储到应用重启后访问的应用数据中。
答案 1 :(得分:0)
如果您需要有关本地异步存储的任何帮助,可以查看此代码。
https://github.com/PiyushGaurav/devkraft-task
它基本上是一个带有登录、注册和主屏幕的应用程序。您可以查看在登录、注册和注销功能中如何使用异步存储。此外,请检查应用如何从本地存储中检查当前登录的用户数据。