【问题标题】:I have the session id in a variable i want to access that variable throughout the application by set the cookie in react native我在一个变量中有会话 id 我想通过在 react native 中设置 cookie 在整个应用程序中访问该变量
【发布时间】:2018-03-28 14:50:39
【问题描述】:

我在{this.state.session} 中有会话ID。 我想通过设置 cookie 或存储异步存储在整个应用程序中调用该会话状态。

能否提供设置异步存储或设置 cookie 的代码?

【问题讨论】:

标签: reactjs react-native


【解决方案1】:

我建议您使用状态管理库,例如 Redux,它可以让您通过 props 访问应用程序中任何位置的变量。如果您仍然需要将会话 ID 存储在 asyncStorage 中,这里是代码

try {
    await AsyncStorage.setItem('SessionId', this.state.session);
} catch (error) {
    // Error saving data
}

尝试将其集中到存储中,这样您就不会到处访问 asyncStorage。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 2010-10-08
    • 2014-07-19
    • 1970-01-01
    • 1970-01-01
    • 2011-12-07
    • 2018-03-24
    相关资源
    最近更新 更多