簡體   English   中英

Redux Uncaught類型錯誤:dispatched action不是函數

[英]Redux Uncaught type error: dispatched action is not a function

我覺得我在這里缺少一些簡單的東西,但無論出於何種原因,這個簡單的ErrorMessageAlert都不會發送動作。 我已多次派遣,我似乎無法弄清楚這個錯誤。

任何人都可以借第二雙眼睛嗎?

這是我的組件

import { connect } from 'react-redux';
import styled from 'react-emotion';
import { resetErrorMessage } from 'users/ducks'


const ErrorMessage = styled.div`
    width: 100%;
    color: red;
    position: fixed;
    background: #F9DADA;
    text-align: center;
    border-bottom: 1px solid red;
    padding-top: 5px;
    padding-bottom: 5px;
    z-index: 1;
`

export class ErrorMessageAlert extends Component<props> {

    state = {  isHidden: true }

    componentDidMount() {
        console.log("triggered")
        // debugger
        const { resetErrorMessageAction } = this.props
        resetErrorMessageAction()
    }

    render(){

        const {
            errorMessage,
        } = this.props

        console.log(this.state.isHidden)
            return (
                <div>
                    {
                        this.state.isHidden && <ErrorMessage>{errorMessage}</ErrorMessage>
                    }
                </div>
            )
    }
}

const mapDispatchToProps = (dispatch) => ({
    resetErrorMessageAction: () => dispatch(resetErrorMessage()),
})

export default connect(null, mapDispatchToProps)(ErrorMessageAlert);

在用戶/鴨子

export const RESET_ERROR_MESSAGE = 'RESET_ERROR_MESSAGE';

export const resetErrorMessage = () => ({
    type: RESET_ERROR_MESSAGE,
})

這是主要的錯誤消息堆棧跟蹤:

ErrorMessageAlert.js:29 Uncaught TypeError: resetErrorMessageAction is not a function
    at ErrorMessageAlert.componentDidMount (ErrorMessageAlert.js:29)
    at ErrorMessageAlert.componentDidMount (react-hot-loader.development.js:654)
    at commitLifeCycles (react-dom.development.js:17334)
    at commitAllLifeCycles (react-dom.development.js:18736)
    at HTMLUnknownElement.callCallback (react-dom.development.js:149)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:199)
    at invokeGuardedCallback (react-dom.development.js:256)
    at commitRoot (react-dom.development.js:18948)
    at react-dom.development.js:20418
    at Object.unstable_runWithPriority (scheduler.development.js:255)
    ```

resetErrorMessageActionundefined因為我從其他文件導入錯誤,因為我使用的是導出默認函數。

所以你需要正確導入文件。

import { ErrorMessageAlert } from 'error/ErrorMessageAlert';

VS

import ErrorMessageAlert from 'error/ErrorMessageAlert';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM