这真的很奇怪&尴尬&我似乎无法理解这里出现了什么问题。React演示组件未收到来自智能组件的MapDispatchToProps
这里是“聪明”的成分:
import { connect } from "react-redux";
import TemplateParent from "../component/svg/TemplateParent";
import { setInitialViewBox } from "../modcon/Actions";
const mapStateToProps = ({ svgTemplateState }) => {
return({
renderType : "Template Selection",
svgTemplateState : svgTemplateState
});
};
const mapDispatchToProps = (dispatch) => {
return({
dispatchSetInitialViewBox : (viewBoxCoOrdinates) => {
dispatch(setInitialViewBox(viewBoxCoOrdinates));
}
});
};
const C_TemSelectionSVGTemplate = connect(mapStateToProps, mapDispatchToProps)(TemplateParent);
export default C_TemSelectionSVGTemplate;
这里是“演示”组件:
import React from "react";
import { calcViewBoxCentre } from "../../modcon/GlobalAPI";
const TemplateParent = React.createClass({
componentDidUpdate : function(){
let getEleDimension = this.gEle.getBBox(),
viewboxValue = calcViewBoxCentre(getEleDimension, 1.75);
/*** ERROR IS HERE: this.props.dispatchSetInitialViewBox is not a function ***/
this.props.dispatchSetInitialViewBox(viewboxValue);
},
render : function(){
/*** the below console logs only shows two props: `renderType` & `svgTemplateState` ***/
console.log(this.props);
return(
<g className = "templateParent"
ref = {(g) => this.gEle = g }>
</g>
);
}
});
我似乎无法弄清楚,为什么mapDispatchToProps
没有被作为道具传递到组件TemplateParent
。
按照要求,这里是行动的创建者setInitialViewBox
:
export const setInitialViewBox = (viewBox) => {
return({
type : SET_INITIAL_VIEWBOX,
svgPayload : {
defaultTab : {
viewBox : viewBox,
scale : 1
},
bodyTab : {
viewBox : viewBox,
scale : 1
},
sleeveTab : {
viewBox : viewBox,
scale : 1
}
}
});
};
不一定相关,但我认为你是出口TemplateParent组件? – Pineda
是的,我是。我不得不简化演示组件'TemplateParent',因为那里正在进行一些计算。但是,是的,这是'出口默认TemplateParent' – Kayote
告诉我们'setInitialViewBox'行动 – lux