我在学习Redux的时候偶然发现了createStore函数。因此,据我所知,createStore接收3个参数:
reducer
initial state
enhancers (for simplicity we will use only middlewares)
但是当我们实际使用createStore时,我们不会传递初始状态作为第二个参数,而是传递带有默认状态的reducer,如下所示:
const initialState = {counter:0}
const reducer =(state=initialState, action)=>...
问题是,为什么我们不把初始状
我想将对象添加到Redux中存在的数组中。如果我不添加redux-persist,代码就可以正常工作,但是在添加redux-persist之后,我得到了一个状态不可迭代的TypeError。我想用redux-persist来运行代码。有没有办法做到这一点? 我的Store代码在添加redux-persist之前: import rootReducer from './reducer';
import {createStore, applyMiddleware} from 'redux';
import thunk from 'redux-thunk
我正在尝试使用redux-persist持久化数据。下面是我的代码:
import { createStore as _createStore, applyMiddleware, compose } from 'redux';
import createMiddleware from './middleware/clientMiddleware';
import { routerMiddleware } from 'react-router-redux';
import {persistStore, autoRehydrate} from
因此,我正在学习如何使用redux和redux persist,目前我陷入了一个问题。每当我试图映射我的商店的内容时,它抛出一个错误,说是TypeError: tasks.map is not a function,我真的不知道为什么会发生这个问题。我搜索了一下,试着调试它,也试着重写代码几次,但都无济于事。下面是我的完整代码: rootReducer.js import React from 'react'
let nextToDo = 0;
const task=[
{
}
]
const reducer =(state=task, action)=&g
初始化redux存储的初始全局状态的不同方法是什么?我看到了的两种方式来设置一个初始的全局状态
假设我们有一个还原器,所有的javascript都在一个文件中。
function rootReducer(state = "Initial Reducer State!", action){
switch(action.type) {
case SET_TEXT:
return "Ignore this case statement it won't run"
default:
return state;
}
我已经看到了分离action和reducer的争论,因为它们具有多对多的关系。
我不认为这实际上适用于Redux。因为只有一个数据存储,所以对reducers的操作应该是一对多。
通常,缩减程序适用于特定数据存储区的特定更改。
MY_ACTION = "MY_ACTION"
function reducer(state, action) {
switch(action.type) {
case MY_ACTION: // stuff with my action to create new state
default: return st
我在学习Redux的工作原理时遇到了很大的困难。我目前收到以下错误:
Warning: Failed propType: Invalid prop `children` of type `object` supplied to `Provider`, expected `function`
Uncaught TypeError: children is not a function
我的代码如下--谁能找出我为什么会得到这个错误?
import React, { Component } from 'react';
import ReactDOM from 'react
我有我的问题。我写了一个流类型检查器来检查我的减速器。有一个错误,你能给我解释一下什么是错误的原因吗?这是我的密码。
// @flow
import {SET_USER} from "./action-types";
import type {SetUserAction} from "./user-actions"; // export type SetUserAction = (user: User) => Action;
export type State = {
+username: ?string,
+firstName: ?str
我似乎不明白为什么我不能更新计数器,即使我发送了正确的操作类型,并且它们处于递增和递减状态。我尝试传递一个mapDispatchToProps并将函数放入该函数中,但仍然得到相同的问题,由于某些原因没有任何东西更新状态。
索引:
import {createStore} from 'redux';
import {Provider} from 'react-redux';
import {reducer} from './src/reducers/counter';
const store = createStore(reducer);
co
我从react开始尝试一些东西。但我不断地得到错误的"Uncaught TypeError: (0 , _reactRedux.combineReducers) is not a function“这是我的演示配置文件
import React from 'react'
import { render } from 'react-dom'
import { createStore, applyMiddleware,compose } from 'redux'
import { Provider } from 'react-redu
我现在正在学习redux。下面共享的代码是独立于React的,因此React集成是不考虑的。
下面是redux-basics.js,它有还原器、商店、操作和订阅部分。
const redux = require('redux');
const createStore = redux.createStore;
// Note : Store Creation is actually dependent on Reducer Thats why reducer must be created first.
// Reducer
const initialState = { co