我查看了很多博客,但没有一个能解决这个错误。有人能解释一下我为什么会犯这个错误吗?我是新来的。我听从了youtube视频中所有的命令。在那段视频中,他没有使用任何地方的调度。你还能告诉我在哪里使用调度吗?src/index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import {Provider} from 'react-redux'
import {createStore} from 're
export default async (state = INITIAL_STATE, action) => {
switch (action.type) {
//... Many other cases
CASE 'A':
CASE 'B':
CASE 'C':
CASE 'D':
CASE 'E':
{
//call http request for logging purpose
return { ...state, isLo
我有一个使用redux-thunk的react项目。我创建了一个将命中端点的操作,然后将store设置为接收到的数据。目前,我正在使用.then,但当我调用componentdidmount中的操作时,数据不在那里。组件在数据可用之前呈现。为了解决这个问题,我决定将我的操作转换为异步操作,然后在我的组件挂载中等待。问题是,一旦我把async放入我的操作中,我就会得到这个错误...
Unhandled Rejection (Error): Actions must be plain objects. Use custom middleware for async actions.
以下是我的代码
使用react-redux而不使用saga或thunk中间件是一种最佳实践吗?
我有一个react-redux应用程序,但它没有任何这些中间件。这是我现在拥有的代码。
import React from 'react';
import ReactDOM from 'react-dom';
import allReducers from './app/reducers/index';
import Header from './app/components/header';
import './index.css'
我不明白为什么需要像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
以下是两个代码示例:
onClick() { // click-handler of a button
axios.get(someUrl)
.then(response => {
// setData is a fn dispatching an action-creator passed through react-redux's connect()
setData(response.data);
});
}
或
// buttonClicked is also a fn dispatching an action-creator
我对这种错误感到困惑,尽管我使用了自变量产品来显示我的所有产品,但是当我试图再次使用它时,我无法捕捉到它,注意到变量是通过redux调用Axios得到的。为什么我不知道:这是我的密码:
import React, {useEffect} from "react";
import Product from "../components/Product";
import LoadingBox from "../components/LoadingBox";
import AlertBox from "../components/AlertBo