Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.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
Redux reducer未被调用_Redux - Fatal编程技术网

Redux reducer未被调用

Redux reducer未被调用,redux,Redux,我正在努力学习Redux。我正在尝试一个测试应用程序,我被这个错误卡住了,不知道为什么reducer没有更新状态。我已经研究了导致这种情况的常见问题,但似乎无法在我的问题中找到这些错误,我的减速器没有改变状态 logItem.js import React from 'react'; import {Link} from 'react-router-dom'; import {connect} from 'react-redux'; import {ad

我正在努力学习Redux。我正在尝试一个测试应用程序,我被这个错误卡住了,不知道为什么reducer没有更新状态。我已经研究了导致这种情况的常见问题,但似乎无法在我的问题中找到这些错误,我的减速器没有改变状态


    logItem.js
    import React from 'react';
    import {Link} from 'react-router-dom';
    import {connect} from 'react-redux';
    import {addCurrent} from '../../actions/logAction';
    
    const LogItem = (props) => {
        const {message, tech, date, attention} = props.singleLog;
    
        console.log(props.currentLog)
    
        const updateLog = (singleLog) => {  
            updateLog(singleLog, singleLog._id)
        }
    
        const current = (singleLog) => {
            console.log(singleLog)
            addCurrent(singleLog)
        }
        return (
            <div>
                <h3>{message}</h3>
                <p className={`text ${attention}`}>was last updated by {tech} on {date}</p> 
                <Link onClick={() => current(props.singleLog)} to='/addLog'>update</Link>
                <button>delete</button>
            </div>
        )
    }
    
    const mapStateToProps = (state) => ({
        currentLog : state.log.current
    })
    
    export default connect(mapStateToProps, {addCurrent})(LogItem);

logReducer.js

export const addCurrent = (singleLog) => {
    console.log(singleLog)
    return({type: SET_CURRENT, payload: singleLog})
}


import { SET_LOADING, GET_LOGS, LOGS_ERROR, ADD_LOG, UPDATE_LOG, SET_CURRENT } from '../actions/types';

const initialState = {
    logs: null,
    loading: true,
    current: null,
    errors: null
}
import { SET_LOADING, GET_LOGS, LOGS_ERROR, ADD_LOG, UPDATE_LOG, SET_CURRENT } from '../actions/types';

const initialState = {
    logs: null,
    loading: true,
    current: null,
    errors: null
}
export default (state = initialState, action) => {
    console.log(action.type)
    switch(action.type) {
        case SET_CURRENT: 
            console.log("5")
            console.log(action.payload)
                return {
                    ...state,
                    current: action.payload,
                    errors:null
            }
        default: 
        return state;
    }
}
试着替换

export const addCurrent = (singleLog) => {
    console.log(singleLog)
    return({type: SET_CURRENT, payload: singleLog})
}


您的操作没有被调度,不知道为什么您声称减速机没有做任何事情,而显然该操作甚至没有被调度。下次请使用redux开发工具,这样您至少可以知道发生了什么,并且可以清楚地提出一个更好的问题


您应该将
addCurrent(singleLog)
替换为
props。addCurrent(singleLog)

您的减速机看起来很好,您确定它已经执行了吗?redux开发工具会怎么说?我也在reducer中尝试了console.log,看看它是否正常工作,但没有。redux开发工具显示状态也没有变化…有没有办法找到问题…谢谢我用你的代码@jun尝试了一下…但对我不起作用…你认为我还有其他方法可以解决这个问题吗…谢谢
export const addCurrent = (singleLog) => dispatch => {
    console.log(singleLog)
    dispatch({type: SET_CURRENT, payload: singleLog})
}