Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 为什么Redux Strore不添加新条目_Reactjs_Redux_React Redux_React Router - Fatal编程技术网

Reactjs 为什么Redux Strore不添加新条目

Reactjs 为什么Redux Strore不添加新条目,reactjs,redux,react-redux,react-router,Reactjs,Redux,React Redux,React Router,我正在关注这一点。我在向Redux商店添加一个条目时遇到问题。 修改如下: const storeNavItemsData = ( data ) => ( { type: "STORE_NAV_ITEMS", data, } ); ....... export function fetchNavItemsData() { return function(dispatch){ return fetchFromExternal( ).then( res => dispatc

我正在关注这一点。我在向Redux商店添加一个条目时遇到问题。 修改如下:

const storeNavItemsData = ( data ) => ( {
type: "STORE_NAV_ITEMS",
data,
 } );

.......

export function fetchNavItemsData() { 
return function(dispatch){
   return fetchFromExternal( ).then( res => dispatch(storeNavItemsData(res)) );
   }
 }
添加了新函数以调用此中的外部系统

我已经像这样修改了文件

import { fetchData, fetchNavItemsData} from "../store";
.....
Home.serverNavFetch = fetchNavItemsData;
..... 
const mapDispatchToProps = {
fetchData,
fetchNavItemsData,
};
现在修改这个

在我看不到Redux存储按预期填充后,值为空

            window.REDUX_DATA = {"loggedIn":true,"data":[],"navItems":[]}

你能告诉我我做错了什么吗

根据回购协议中的代码,尝试添加新的缩减器以添加新的存储实体-

const reducer = combineReducers( {
    loggedIn: sessionReducer,
    data: dataReducer,
    navData : navReducer // new reducer added here
} );

navReducer.js // this is the reducer file
const dataReducer = ( state = [ ], action ) => {
    switch ( action.type ) {
        case "STORE_NAV_ITEMS":
            return action.data;
        default: return state;
    }
};
要访问存储在redux存储中的值,请将存储映射到组件文件-

const mapStateToProps = ( state ) => ( {
navData: state.navData,
});

现在,在此之后,您可以访问props-
this.props.navData的值

根据回购协议中的代码尝试添加新的缩减器以添加新的存储实体-

const reducer = combineReducers( {
    loggedIn: sessionReducer,
    data: dataReducer,
    navData : navReducer // new reducer added here
} );

navReducer.js // this is the reducer file
const dataReducer = ( state = [ ], action ) => {
    switch ( action.type ) {
        case "STORE_NAV_ITEMS":
            return action.data;
        default: return state;
    }
};
要访问存储在redux存储中的值,请将存储映射到组件文件-

const mapStateToProps = ( state ) => ( {
navData: state.navData,
});

现在,您可以以props-
this.props.navData

的形式访问该值。redux开发工具可以提供有价值的信息,例如:操作是否已调度以及操作是否导致状态更改。redux开发工具可以提供有价值的信息,例如:操作是否已调度以及操作是否导致状态更改。