redux

How can i access to redux store with react navigation?

风格不统一 提交于 2020-02-26 04:17:49
问题 I have App "Music App" for tow users type "Guest, a user registered" I have a bottom navigator for those, When Guest opens my app I want to render just 4 bottom tabs "Home, browse, search, radio". but when user login/register I want to render 5 tabs previously tabs plus "Library" Tab. SO I dispatch action when user register\login , and change isLogin state from false to true and work some stuff like add some other data to my drawer and it appears fine tho, I want to access to redux store

How can i access to redux store with react navigation?

戏子无情 提交于 2020-02-26 04:17:07
问题 I have App "Music App" for tow users type "Guest, a user registered" I have a bottom navigator for those, When Guest opens my app I want to render just 4 bottom tabs "Home, browse, search, radio". but when user login/register I want to render 5 tabs previously tabs plus "Library" Tab. SO I dispatch action when user register\login , and change isLogin state from false to true and work some stuff like add some other data to my drawer and it appears fine tho, I want to access to redux store

Component won't update when a redux state change occurs

前提是你 提交于 2020-02-26 03:41:49
问题 case 'ADD_TO_CART': { let item = action.payload; let newState = addToCart(state, item); return newState; } const increaseItem = (array = [], dish) => { array.filter((item) => { if (item.id === dish.id) { item.quantity++; } }); return array; } case 'INCREASE_ITEM': { let item = action.payload; console.log('run in increase') let newState = increaseItem(state, item); return newState; } Here is the code. Problem is when the properties quantity increase, redux think the state has no change so

Component won't update when a redux state change occurs

十年热恋 提交于 2020-02-26 03:41:05
问题 case 'ADD_TO_CART': { let item = action.payload; let newState = addToCart(state, item); return newState; } const increaseItem = (array = [], dish) => { array.filter((item) => { if (item.id === dish.id) { item.quantity++; } }); return array; } case 'INCREASE_ITEM': { let item = action.payload; console.log('run in increase') let newState = increaseItem(state, item); return newState; } Here is the code. Problem is when the properties quantity increase, redux think the state has no change so

小白关于Redux 的一点学习总结

五迷三道 提交于 2020-02-25 21:46:43
Redux Redux 是一个状态管理工具,由 flux 演变而来,但它相对来说更容易上手。通过创建一个仓库,存储操作 view 层的状态,实现状态的共享,操作状态的变化实现页面渲染。使用 Redux 可以使组件间的数据交互更加方便,对于项目的开发和后期维护也会更加方便。 Redux 的应用范围 由于Redux 的功能在于对组件的状态进行集中的管理,当组件间的状态传递较为简单,页面的渲染与状态间的交互较少较简单时,不必使用 Redux 。因此,可以在以下几种情况下使用 Redux: 1. 某个组件的状态需要共享 2. 某个状态需要在任何地方都可以拿到 3. 一个组件需要改变全局状态 4. 一个组件需要改变另一个组件的状态 Redux 的三大原则 单一数据源(store是唯一的) state 是只读的(不能对state进行修改) 使用纯函数(reducer)执行修改 Redux 的使用 下面开始使用 Redux 安装 redux npm i redux yarn add redux 在 src 文件夹中创建一个 store 文件夹,添加 index.js 和 reducer.js 文件 在 index.js 文件中引入 createStore 方法,创建一个 store 并导出 import { createStore } from 'redux' import reducer

解决页面刷新redux数据丢失问题。

眉间皱痕 提交于 2020-02-25 20:30:42
概念 对于目前普遍的“单页应用”,其中的好处是,前端可以从容的处理较复杂的 数据模型 ,同时基于数据模型可以进行变换,实现更为良好的交互操作。 良好的交互操作背后,其实是基于一个对应到页面组件状态的模型,随便称其为 UI模型 。 数据模型对应的是后端数据库中的业务数据,UI模型对应的是用户在浏览器一系列操作后组件所呈现的状态。 这两个模型不是对等的! 比如下图中这个管控台(不存在所谓的子页面,来进行单页路由的切换,而是一个类似portal的各块组件的切换): 我们构建的这个单页应用,后端的数据库和提供的接口,是存储和管理数据模型的状态。 但是用户操作管控台中,左侧面板的打开/关闭、列表选中的项目、编辑面板的打开等,这些UI模型的状态均不会被后端记录。 现象 当用户强制进行页面刷新,或者关闭页面后又再次打开时,单页应用虽然能从后端拉取数据记录,但是页面组件的状态已经无法恢复了。 目前,多数的单页应用的处理,就是在页面刷新或重新打开后,抛弃之前用户操作后的状态,进到一个初始状态。(当然,如果涉及较多内容编辑的,会提示用户先保存等等) 但这样,显然是 对交互的一种妥协 。 方案设计 技术场景 我们的单页应用是基于Redux+React构建。 组件的 大部分状态 (一些非受控组件内部维护的state,确实比较难去记录了)都记录在Redux的store维护的state中。

React & Redux 实战 Reminder Pro 项目(5 个视频)

▼魔方 西西 提交于 2020-02-25 17:17:17
React & Redux 实战 Reminder Pro 项目(5 个视频) React & Redux 实战 Reminder Pro 项目 #1 项目搭建 「07:03」 React & Redux 实战 Reminder Pro 项目 #2 显示列表 「09:45」 React & Redux 实战 Reminder Pro 项目 #3 处理时间 「Pro」「04:23」 React & Redux 实战 Reminder Pro 项目 #4 删除 reminder 「Pro」「05:57」 React & Redux 实战 Reminder Pro 项目 #5 保存数据到 cookies(完结) 「Pro」「04:36」 来源: oschina 链接: https://my.oschina.net/u/2417355/blog/3168657

React + Redux - dispatching an action in dumb component?

家住魔仙堡 提交于 2020-02-24 10:53:28
问题 I started learning Redux and the whole idea looks neat, but after rebuilding my React app from "normal" to "redux-way" this problem came up. I have a list of if items that I build based on JSON from async call. Then every item on that list sends an async call on click and returns something. Before my app was pretty straightforward: components/list/List.jsx components/list/ListItem.jsx Right now it looks like this: footer/list/ListContainer.jsx // here I run an async call and generate list

React-Redux之API

北城以北 提交于 2020-02-24 10:21:01
connect ( [mapStateToProps ] , [mapDispatchToProps ] , [mergeProps ] , [options ] ) 连接 React 组件与 Redux store。 连接操作不会改变原来的组件类,反而 返回 一个新的已与 Redux store 连接的组件类。 参数 [ mapStateToProps (state , [ownProps ] ) : stateProps ] ( Function ): 如果定义该参数,组件将会监听 Redux store 的变化。任何时候,只要 Redux store 发生改变, mapStateToProps 函数就会被调用。该回调函数必须返回一个纯对象,这个对象会与组件的 props 合并。如果你省略了这个参数,你的组件将不会监听 Redux store。如果指定了该回调函数中的第二个参数 ownProps ,则该参数的值为传递到组件的 props,而且只要组件接收到新的 props, mapStateToProps 也会被调用。 [ mapDispatchToProps (dispatch , [ownProps ] ) : dispatchProps ] ( Object or Function ): 如果传递的是一个对象,那么每个定义在该对象的函数都将被当作 Redux action

React/Redux animations based on actions

假装没事ソ 提交于 2020-02-24 09:28:48
问题 Having more or less completed my first React+Redux application, I have come to the point where I would like to apply animations to various parts of the application. Looking at existing solutions, I find that there is nothing even close to what I would like. The whole ReactCSSTransitionGroup seems to be both an intrusive and naive way to handle animations. Animation concerns bleed out of the component you want to animate and you have no way to know anything about what happens in the