百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

redux-offline

> 前端框架
开源

构建面向 Web 和 React Native 的离线优先应用

6.1K stars0 点赞2 次浏览
访问官网GitHub

工具介绍

构建面向 Web 和 React Native 的离线优先应用

招募维护者


为 Reasonaboutable:tm: 离线优先(Offline-First)应用提供持久化的 Redux 存储,并对乐观 UI(optimistic UI)提供一流支持。可与 React、React Native 配合使用,或作为任何 Web 应用的独立状态容器。

Redux Offline 现在由社区驱动的团队维护。该库的新版本将通过 npm 组织 @redux-offline 发布。特别感谢 @jevakallio 最初创建了这么出色的库。

快速开始

1. 使用 npm(或 Yarn)安装
适用于 React Native 0.60+
bash
npm install --save @redux-offline/redux-offline@native

适用于 React Native Expo SDK 36

bash
npm install --save @redux-offline/redux-offline@expo

适用于 React Native <= 0.59

bash
npm install --save @redux-offline/redux-offline
2. 使用 compose 添加 offline store 增强器
javascript

import { applyMiddleware, createStore, compose } from 'redux';
import { offline } from '@redux-offline/redux-offline';
import offlineConfig from '@redux-offline/redux-offline/lib/defaults';

// ...

const store = createStore(
  reducer,
  preloadedState,
  compose(
    applyMiddleware(middleware),
    offline(offlineConfig)
  )
);
3. 为 action 添加 offline 元数据
javascript
const followUser = userId => ({
  type: 'FOLLOW_USER_REQUEST',
  payload: { userId },
  meta: {
    offline: {
      // the network action to execute:
      effect: { url: '/api/follow', method: 'POST', json: { userId } },
      // action to dispatch when effect succeeds:
      commit: { type: 'FOLLOW_USER_COMMIT', meta: { userId } },
      // action to dispatch if network action fails permanently:
      rollback: { type: 'FOLLOW_USER_ROLLBACK', meta: { userId } }
    }
  }
});

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScripthacktoberfestoffline-capablereactreact-native

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架