Javascript Mapdispatchtoprops不提供道具功能 import React,{Component}来自“React”; 从“道具类型”导入道具类型; 从“react redux”导入{connect}; 从“/shelf-modal”导入{ShelfModal}; 从“../../../redux/actions/shelf-modal”导入{openShelfModal}”; 导出类ShelfTest扩展组件{ 建造师(道具){ 超级(道具); } render(){ const{openModal}=this.props; 返回( 开架 ); } } 导出常量mapDispatchToProps=dispatch=>({ OpenModel:()=>调度(OpenShelfModel()) }); export const mapStateToProps=state=>{ 返回{ }; }; 导出默认连接( MapStateTops, mapDispatchToProps )(搁置期);

Javascript Mapdispatchtoprops不提供道具功能 import React,{Component}来自“React”; 从“道具类型”导入道具类型; 从“react redux”导入{connect}; 从“/shelf-modal”导入{ShelfModal}; 从“../../../redux/actions/shelf-modal”导入{openShelfModal}”; 导出类ShelfTest扩展组件{ 建造师(道具){ 超级(道具); } render(){ const{openModal}=this.props; 返回( 开架 ); } } 导出常量mapDispatchToProps=dispatch=>({ OpenModel:()=>调度(OpenShelfModel()) }); export const mapStateToProps=state=>{ 返回{ }; }; 导出默认连接( MapStateTops, mapDispatchToProps )(搁置期);,javascript,reactjs,redux,react-redux,Javascript,Reactjs,Redux,React Redux,上面是我正在使用的模式的代码。我正在尝试将mapDispatchToProps中的OpenModel函数作为props呈现在中,但它没有显示在props中。操作从正确的路径导入。这里出了什么问题?您不需要同时导出MapStateTrops和mapDispatchToProps,因为您可以通过connect将它们与ShelfTest一起导出 我还重新构建了您的mapDispatchToProps,以获得良好的效果 import React, { Component } from "react";

上面是我正在使用的模式的代码。我正在尝试将
mapDispatchToProps
中的
OpenModel
函数作为
props
呈现在
中,但它没有显示在
props
中。操作从正确的路径导入。这里出了什么问题?

您不需要同时导出
MapStateTrops
mapDispatchToProps
,因为您可以通过
connect
将它们与
ShelfTest
一起导出

我还重新构建了您的
mapDispatchToProps
,以获得良好的效果

import React, { Component } from "react";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import { ShelfModal } from "./shelf-modal";
import { openShelfModal } from "../../../redux/actions/shelf-modal";

export class ShelfTest extends Component {
  constructor(props) {
    super(props);
  }


  render() {
    const { openModal } = this.props;


    return (
      <div>
        <button onClick={openModal}>Open Shelf</button>

        <ShelfModal />
      </div>
    );
  }
}

export const mapDispatchToProps = dispatch => ({
         openModal: () => dispatch(openShelfModal())
       });

export const mapStateToProps = state => {
  return {
  };
};

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(ShelfTest);
只要您的中间件/路由设置正确,这应该可以工作


如果在底部使用
connect
导出组件,则不需要在顶部导出类ShelfTest extensed组件{
,也不需要在通过
connect
导出组件时同时导出
mapstatetops
mapsdispatchtoprops

我还重新构建了您的
mapDispatchToProps
,以获得良好的效果

import React, { Component } from "react";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import { ShelfModal } from "./shelf-modal";
import { openShelfModal } from "../../../redux/actions/shelf-modal";

export class ShelfTest extends Component {
  constructor(props) {
    super(props);
  }


  render() {
    const { openModal } = this.props;


    return (
      <div>
        <button onClick={openModal}>Open Shelf</button>

        <ShelfModal />
      </div>
    );
  }
}

export const mapDispatchToProps = dispatch => ({
         openModal: () => dispatch(openShelfModal())
       });

export const mapStateToProps = state => {
  return {
  };
};

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(ShelfTest);
只要您的中间件/路由设置正确,这应该可以工作


您也不需要导出类ShelfTest扩展组件{如果您使用
connect

将其导出到底部,请在顶部使用{谢谢,但我仍然停留在原始问题上,如果您将
调试器
放在
const-mapsdispatchtoprops=dispatch=>{
openShelfModal是什么样子的?我更新了答案,尝试用这种方式临时映射
openShelfModal
。否则可能是您的操作或中间件/路由有问题。我检查了这个,它仍然不起作用,我如何调试中间件/路由。有指针吗?我还注意到您不需要d
导出类ShelfTest扩展组件{
在顶部如果您使用
connect
在底部导出它。至于指针,您的中间件是如何设置的?您使用的是redux sagas吗?如果
OpenShelfModel
mapDispatchToProps
中为零,则该函数的导入或导出可能有问题。如果您添加的操作是谢谢,但我仍然停留在最初的问题上,dispatchtoprops中的OpenModel函数仍然不能作为Renderi中的道具使用。如果您在
const mapDispatchToProps=dispatch=>{
openShelfModal是什么样子的?我更新了答案,尝试用这种方式临时映射
openShelfModal
。否则可能是您的操作或中间件/路由有问题。我检查了这个,它仍然不起作用,我如何调试中间件/路由。有指针吗?我还注意到您不需要d
导出类ShelfTest扩展组件{
在顶部如果您使用
connect
在底部导出它。至于指针,您的中间件是如何设置的?您使用的是redux sagas吗?如果
OpenShelfModel
mapDispatchToProps
中为零,则该函数的导入或导出可能有问题。如果您添加的操作是可能会有帮助。您在控制台中有错误吗?您在控制台中有错误吗?
export default connect(mapStateToProps, {openShelfModal}) (ShelfTest);