Reactjs Redux-全局概念-显示消息取决于布尔值

Reactjs Redux-全局概念-显示消息取决于布尔值,reactjs,redux,connect,Reactjs,Redux,Connect,我对Redux有问题,我找不到哪里出了问题。我的想法是:我想显示一条消息,这取决于我的数据库中是否已经存在该用户。我使用了redux react,但它对我来说真的很混乱。 1-我的行动 import { SET_MESSAGE_SUBMIT} from "./types"; export const msgRegisterSuccess = () => { return { type: SET_MESSAGE_SUBMIT }; }; 2-我的减速机 i

我对Redux有问题,我找不到哪里出了问题。我的想法是:我想显示一条消息,这取决于我的数据库中是否已经存在该用户。我使用了redux react,但它对我来说真的很混乱。 1-我的行动

import { SET_MESSAGE_SUBMIT} from "./types";

export const msgRegisterSuccess = () => {
    return {
       type: SET_MESSAGE_SUBMIT
    };
 };
2-我的减速机

import {SET_MESSAGE_SUBMIT} from "../actions/types";

export default function (state=false,action){
   switch(action.type){
      case SET_MESSAGE_SUBMIT:
         return !state.submitToggle;

      default:
         return state;
   }
};
3-我的容器

import React, { useState} from "react";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import { registerUser } from "../../actions/registerActions";

import Validate from "../../components/form/Validate";
import Contact from "../../components/auth/Contact";

const ContactPage = ({ registerUser}) => {
   const [user, setUser] = useState({
      user_name: "",
      email: "",
      message: "",
      errors: {}
   });

   const handleChange = e => {
      setUser({
         ...user,
         [e.target.name]: e.target.value
      });
   };

   const handleBlur = e => {
      const { name, value } = e.target;
      const err = { ...user.errors, ...Validate(name, value).errors };
      setUser({ ...user, errors: { ...err } });
   };

   const handleSubmit = e => {
      e.preventDefault();
      const { user_name, email, message} = user;
      registerUser({ user_name, email, message});
   };

   return (

      <div>
         <Contact
            user={{ ...user}}
            onBlur={handleBlur}
            onChange={handleChange}
            onSubmit={handleSubmit}
         />

      </div>

   );
};

ContactPage.propTypes = {
   registerUser: PropTypes.func.isRequired,
   toggle: PropTypes.object.isRequired,
   errors: PropTypes.object.isRequired
};

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

export default connect(
   mapStateToProps,
   { registerUser }
)(ContactPage);
有人能帮我吗


我看到这个州有些不一致

这里是布尔值

导出默认函数(state=false,action){

这里返回状态或布尔值

   switch(action.type){
      case SET_MESSAGE_SUBMIT:
         return !state.submitToggle;

      default:
         return state;
   }
但在组件中,您需要对象

const mapStateToProps = state => ({
   errors: state.errors,
   toggle: state.toggle
});
我并没有亲自尝试所有的代码,但其他人认为似乎可以

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