redux

combineReducers doesn't infer type

断了今生、忘了曾经 提交于 2020-02-16 03:59:14
问题 I am using combineReducers in my React TypeScript app: // combinedReducer.ts import { combineReducers } from 'redux' import reducer1 from './reducer1' import reducer2 from './reducer2' const combinedReducer = combineReducers({ reducer1, reducer2, }) export default combinedReducer I understand from redux documentation that combineReducers should infer it's type based on the combined reducers. However, for me it does not, even though each combined reducer has its return type recognised: (

combineReducers doesn't infer type

不打扰是莪最后的温柔 提交于 2020-02-16 03:58:27
问题 I am using combineReducers in my React TypeScript app: // combinedReducer.ts import { combineReducers } from 'redux' import reducer1 from './reducer1' import reducer2 from './reducer2' const combinedReducer = combineReducers({ reducer1, reducer2, }) export default combinedReducer I understand from redux documentation that combineReducers should infer it's type based on the combined reducers. However, for me it does not, even though each combined reducer has its return type recognised: (

Inferring mapped props when using TypeScript and React-Redux

不羁岁月 提交于 2020-02-15 20:23:11
问题 I found a way to get type safety when using mapStateToProps from react-redux : as documented you can define an interface and parameterize React.Component<T> with your interface. However, when I am defining mapStateToProps , I'm already defining a function where the types of the properties of the resulting object can be inferred. Eg, function mapStateToProps(state: MyState) { return { counter: state.counter }; } Here, the prop counter can be inferred to be the same type as state.counter . But

Inferring mapped props when using TypeScript and React-Redux

 ̄綄美尐妖づ 提交于 2020-02-15 20:22:33
问题 I found a way to get type safety when using mapStateToProps from react-redux : as documented you can define an interface and parameterize React.Component<T> with your interface. However, when I am defining mapStateToProps , I'm already defining a function where the types of the properties of the resulting object can be inferred. Eg, function mapStateToProps(state: MyState) { return { counter: state.counter }; } Here, the prop counter can be inferred to be the same type as state.counter . But

Redux store changes when reload page

烈酒焚心 提交于 2020-02-15 18:02:19
问题 I am implementing login with two different type of users using react redux. This is my login method: export const login = (credentials) => (dispatch) => api.user.login(credentials).then(user => { localStorage.userJWT = user.token; localStorage.userEmail = user.email; localStorage.userId = user.id; localStorage.surname = user.surname; localStorage.type = user.type; dispatch(userLoggedIn(user)); }); For the first type of user, I return from backend: token, email, id, surname. For the second

Redux store changes when reload page

牧云@^-^@ 提交于 2020-02-15 18:02:01
问题 I am implementing login with two different type of users using react redux. This is my login method: export const login = (credentials) => (dispatch) => api.user.login(credentials).then(user => { localStorage.userJWT = user.token; localStorage.userEmail = user.email; localStorage.userId = user.id; localStorage.surname = user.surname; localStorage.type = user.type; dispatch(userLoggedIn(user)); }); For the first type of user, I return from backend: token, email, id, surname. For the second

React Native Redux(二)-Redux使用

我的未来我决定 提交于 2020-02-10 01:27:11
前言: redux重构(一) 的时候大概讲了 redux 的各个部分的定义,这一部分主要讲解一下 redux 的具体使用。 项目地址 后端 LeanCloud redux 使用 1.项目目录结构 redux能用到的结构都在图上提现出来了,下面将以Login为例介绍每部分的具体内容 2. ActionTypes - 统一定义了action供别处调用 123 export const ERROR_ACTION = 'ERROR_ACTION';export const LOGIN_PERFORM_ACTION = 'LOGIN_PERFORM_ACTION';export const LOGIN_ACTION = 'LOGIN_ACTION'; 3. LoginAction - 事件的发起者 12345678910111213141516171819202122232425262728293031323334353637 import NetUtil from '../utils/NetUtil';import * as types from '../constants/ActionTypes';import Global from '../constants/Global'; export function (username, password) { return

react-thunk

為{幸葍}努か 提交于 2020-02-10 01:15:56
简介 在 reducers 中的所有操作都是同步的并且是纯粹的,即 reducer 都是纯函数,纯函数是指一个函数的返回结果只依赖于它的参数,并且在执行过程中不会对外部产生副作用,即给它传什么,就吐出什么。但是在实际的应用开发中,可能希望做一些异步的(如Ajax请求,异步获取数据,访问浏览器缓存)且不纯粹的操作(如改变外部的状态),这些在函数式编程范式中被称为“副作用”。 Redux 的作者将这些副作用的处理通过提供中间件的方式让开发者自行选择进行实现。 redux-thunk 和 redux-saga 是 redux 应用中最常用的两种异步流处理方式。 redux-thunk中间件可以让action创建函数先不返回一个action对象,而是返回一个函数,函数传递两个参数(dispatch,getState),在函数体内进行有负作用的业务逻辑封装,处理完所需的异步操作后,再发送其它 action 去修改 state。 使用方式 安装:npm install redux-thunk –save-dev 导入thunk: import thunk from ‘redux-thunk’ 导入中间件: import {createStore,applyMiddleware} from ‘redux’ 创建store:let store = createStore(reducer函数

How to update single value inside specific json array item using redux (Flatlist item click)?

戏子无情 提交于 2020-02-06 07:41:08
问题 I have a Flatlist with displaying name and status, I want to toggle status of the user by clicking the flatlist item click. I have created the redux action and redux reducer for this purpose .But unable to change the curresponding status. itemClick (item,index) { const value=false; this.props.listItemClick({props:'status',value}); } export default (state = INITIAL_STATE, action) => { switch (action.type) { case LIST_CLICK: console.log(action.payload.props); return {...state,[action.payload

How to update single value inside specific json array item using redux (Flatlist item click)?

你离开我真会死。 提交于 2020-02-06 07:41:01
问题 I have a Flatlist with displaying name and status, I want to toggle status of the user by clicking the flatlist item click. I have created the redux action and redux reducer for this purpose .But unable to change the curresponding status. itemClick (item,index) { const value=false; this.props.listItemClick({props:'status',value}); } export default (state = INITIAL_STATE, action) => { switch (action.type) { case LIST_CLICK: console.log(action.payload.props); return {...state,[action.payload