我是这堆东西的新手。我见过很多其他关于这个的问题,并且读过Thunk文档,但是我不能把它缝合在一起。
当我运行下面的代码时,我得到了错误"Actions必须是普通对象,使用自定义中间件进行异步操作“,这正是我试图用Thunk解决的问题。
我的行动看起来是这样的:
src/actions/recipes.js
// this calls the API
function fetchApiGetRecipes() {
return fetch('https://mywebsite.com/endpoint/', {
method: 'GET',
我正在尝试使用move my app将redux-react从纯react转换为redux-react。我为onClick创建了一个action和reducer,但是在尝试在开发模式下启动应用程序后,我得到了这个错误
Uncaught TypeError: Cannot read property 'type' of undefined at reducerDomMethods (manMethodsReducers.js:12)
哪一条是这条线?
switch (action.type) {
这是我的代码
减速机
export default function redu
这是来自easy文档的示例代码,但是redux-工具箱中的createThunk也有相同的问题:
function MyComponent() {
const saveTodo = useStoreActions(actions => actions.todos.saveTodo);
const onSaveClick = useCallback(
// We chain on the promise returned by dispatching the thunk
//
() =>
我将redux-thunk用于异步操作,babel-polyfill用于承诺。我得到以下错误:Error: Actions must be plain objects. Use custom middleware for async actions.
我通过在中间件中包含redux-promise来解决这个问题。我不知道为什么我必须使用redux-promise来解决这个问题,因为Redux中的所有示例都使用babel-polyfill。我是否应该继续使用redux-promise,或者我可能对babel-polyfill有一些问题?
babel-polyfill包含在我的应用程序入口点:
i
我遇到了这个错误,并花了几个小时试图找出它。我看过所有看似重复的问题,但它们不能解决这个问题。
在我的react/redux应用程序中,当我在一个操作中发出ajax请求时,它会抛出以下错误:Uncaught Error: Actions must be plain objects. Use custom middleware for async actions.
我的商店设计如下:
import { composeWithDevTools } from 'redux-devtools-extension';
import reducers from './reduc
我有下面的代码,我的redux商店和一切正常工作时,与预期的有线反应。现在,我试图在动作分派器中访问存储的当前状态(除了react之外),但是当我在初始分派之后使用它时,我得到的是空值。
import configureStore from '../../common/store/configureStore';
const history = createHistory();
const reduxRouterMiddleware = syncHistory(history);
// Create a new Redux store instance
const store
我使用的redux-promise-middleware和redux-thunk都是这样的:
import { applyMiddleware, compose, createStore } from 'redux'
import thunk from 'redux-thunk';
import promise from 'redux-promise-middleware'
import logger from 'redux-logger'
import reducer from './reducers'
c
我在用模拟商店测试雷鸣时遇到了麻烦。
在我的示例中,我调用getState()来获取redux存储的状态,然后根据状态分派操作。
如何让getState()调用来检查模拟存储状态,而不是redux状态?
import {initialState} from '../configureStore'
import {saveAndSendTask} from '../thunks/queueThunk'
import configureMockStore from 'redux-mock-store'
import t
我正在尝试使用next-redux-wrapper存储从Next.js中的getServerSideProps分派一个thunk。但是,我一直收到以下typescript错误: TS2345: Argument of type '(dispatch: any) => Promise<any>' is not assignable to parameter of type 'AnyAction'. Property 'type' is missing in type '(dispatch: any) => Pr
我不明白为什么需要像redux-thunk这样的东西。据我所知,thunk是一个返回函数的函数。在我看来,包装的表达式和中间件的使用似乎更多地混淆了正在发生的事情。摘自redux-thunk的示例代码
import thunk from 'redux-thunk';
// Note: this API requires redux@>=3.1.0
const store = createStore(
rootReducer,
applyMiddleware(thunk)
);
// Meet thunks.
// A thunk is a function
我对类型记录中Redux的语法有点困惑。我对打字很陌生,但对它有很好的把握,但有一个特别的部分我不明白。
下面是redux-thunk的类型定义文件:
import { Middleware, Action, AnyAction } from "redux";
export interface ThunkDispatch<S, E, A extends Action> {
<T extends A>(action: T): T; // I don't understand this line
<R>(asyncAction:
我遵循了官方的Redux指南来创建我的thunk操作创建器,这样我就可以在我的react组件中使用绑定的操作。但是,我的组件不能识别函数返回promise,所以我不能使用then,这也意味着我不能访问函数的返回值。 以下是我的操作创建器代码示例: // Temp State for now, not important
type IAppState = any;
// Just a sample response object
interface ISampleThunkResponse {
text: string;
active: boolean;
}
// Thunk ac