简体   繁体   English

"Redux 没有从 mock API 获取数据"

[英]Redux not fetching the data from mock API

Before posting this, I have looked at other 7-8 titles naming my problem, but I have not found a solution after hours to trying to figure it out by myself.在发布此之前,我查看了其他 7-8 个标题命名我的问题,但我在几个小时后没有找到解决方案,试图自己解决这个问题。 So I apologize if it is something obvious and I am just not getting it.因此,如果这是显而易见的事情,我很抱歉,我只是不明白。 I am trying to implement Redux in my project.我正在尝试在我的项目中实现 Redux。 I have a fetch action function not firing in UseEffect at all.我有一个 fetch 操作函数根本没有在 UseEffect 中触发。 Also as a result, the reducer is not working since it is down the chain of the logic.因此,reducer 无法工作,因为它位于逻辑链的下游。 This is the fetch action function:这是获取操作函数:

> export const FetchUserData = () => (dispatch) => {
>     console.log('fetching the data');   fetch("http://localhost:4500/quote")
>       .then(response => response.json())
>       .then(data => {
>           console.log(data);
>           dispatch ({
>               type: 'FETCH_USERDATA',
>               payload: data
>           });
>       });
> 
> };

in your store can you add the following?在您的商店中,您可以添加以下内容吗?

import { createStore, applyMiddleware} from 'redux';

const store = createStore(allReducers, applyMiddleware(thunkMiddleware))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM