函数内部的访问分派

问题描述 投票:0回答:1

我希望我的函数“ VerifyEmailResend”能够访问mapDispatchToProps内部的两个调度方法。我该怎么办?

VerifyEmailResend()已导出,因为我希望在整个应用程序中都可以调用它。

此应用是使用Redux在React中编写的。

我通常知道使用connect方法,但是connect是专门用于对组件进行反应的。我在这里缺少类似的东西吗?

const mapDispatchToProps = dispatch => ({
    onSetVerifyEmailResent: verifyEmailResent =>
        dispatch({ type: 'VERIFY_EMAIL_RESENT_SET', verifyEmailResent }),
    onSetVerifyEmailVerified: verifyEmailVerified =>
        dispatch({ type: 'VERIFY_EMAIL_RESENT_VERIFIED', verifyEmailVerified })
})

export const VerifyEmailResend = () => () => {
    api.user.resendEmailVerification().then(data => {
        if (data.resent) {
            //onSetVerifyEmailResent(true)
        }
        if (data.verified) {
            //onSetVerifyEmailVerified(false)
        }
    })
}
reactjs redux react-redux
1个回答
0
投票

我不确定您对此感到困惑。但是你可以做到:

const VerifyEmailResend = () => {}
export default connect(null, mapDispatchToProps)(VerifyEmailResend)
© www.soinside.com 2019 - 2024. All rights reserved.