【问题标题】:Storing database json file in optimal way for react native app以最佳方式存储数据库 json 文件以响应本机应用程序
【发布时间】:2019-06-06 07:20:21
【问题描述】:

我正在使用 react native、redux 和 firebase,我有一个 1 MB 的数据库导出,其中包含来自加拿大营养文件数据库的食物营养信息。

此数据永远不会改变,并用于用户可以搜索和导入的 FlatList。

对我来说,存储这些信息以供用户在搜索时尽快访问的最佳方式是什么?

我正在考虑简单地将 json 文件包含在我的其他源文件中,并使用 require 从那里调用它。

但是由于我已经设置了 firebase 和 redux,我想知道是否出于某种原因考虑这些选项是否更有意义。

提前感谢您的任何意见。

【问题讨论】:

  • 据我所知,从文件导入将是最好的解决方案。如果将数据存储在 redux 存储中,则 wont be cleared from memory until you kill the app. If you store it in a file you can import wherever your want and when the component is unmounted, whatever youve 导入的数据将从内存中清除。

标签: json firebase react-native redux react-native-flatlist


【解决方案1】:

由于您已经在使用 redux,我会在 app init/mount 上将 json 内容添加到商店,这样您就可以从任何地方轻松获取它。

我会考虑的其他选择:

  1. 在运行时导入、解析和渲染 JSON 文件(因为它永远不会改变);
  2. 使用 AsyncStorage 使其在本地数据库中可用,但在 redux 存储之外。

【讨论】:

    猜你喜欢
    • 2011-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 2012-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多