是否有用于本机反应的简单同步存储选项? [英] Is there a simple Synchronous Storage option for react native?

查看:39
本文介绍了是否有用于本机反应的简单同步存储选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 React Native 应用有一个同步存储用例.

I have a use case for synchronous storage for my react native app.

在应用呈现主页视图之前,我想检查本地存储中是否存储了会话令牌,如果可用则继续,否则想将登录组件呈现为初始视图.

Before app renders a home view, I want to check if there is a session token stored on the local storage and proceed if it is available, otherwise want to render login component instead as the initial view.

使用同步存储将简化代码.

Using sync storage will simplify the code.

推荐答案

我认为没有简单的同步存储选项.根据 this 回答 localstorage 未在核心 IOS 中实现JavaScript 引擎.AFAIK 其他选项,例如 this localstorage polyfill 中使用的选项不起作用.这让我们需要一个在设计上是异步的 React Native 模块.来自文档:

I don't think there is a simple synchronous storage option. According to this answer localstorage is not implemented in the core IOS javascript engine. AFAIK the other options such as those used in this localstorage polyfill don't work. That leaves us with needing a react native module which are asynchonous by design. From the docs:

React Native Bridge 是异步的,因此将结果传递给 JavaScript 的唯一方法是使用回调或发出事件

React Native bridge is asynchronous, so the only way to pass a result to JavaScript is by using callbacks or emitting events

所以我认为异步是要走的路.

So I think Async is the way to go.

这篇关于是否有用于本机反应的简单同步存储选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆