도움이 필요합니다. 내 colorcontrol에서 나는 행운과 this.props.dispatch(triggerFBEvent(fbID, method, params))
할려고 노력하고있다. 그래도 작동하려면 그냥 triggerFBEvent(fbID, method, params)
을 수행해야합니다. index.bundle.js:61968 Uncaught TypeError: this.props.dispatch is not a function
구성 요소 props.dispatch가 작동하지 않습니다. 반응 redux
무엇을 달성하려고하는 것은 위의 라인과 새로운 소품에 보낼 수 있도록하고, 다음
에componentWillMount() { this.props.dispatch(fetchFBEvent(this.props.fbID, "getColor")) }
전화 사용자 정의 서비스 업데이트 : 나는 오류를 얻고있다 상태와 적절한 색상. 그러나 this.props.dispatch는 거기에있는 함수가 아닙니다.
import React from 'react'
import { connect } from 'react-redux'
import {triggerFBEvent, triggerFBClearEvent, fetchFBEvent} from '../actions/functionblocksActions'
`
import { CustomPicker, HuePicker, SaturationPicker, SliderPicker, CustomPointer } from 'react-color';
@connect((store) => {
return {
fb: store.functionblocks.functionblock
}
})
export default class Functionblock extends React.Component {
constructor(props) {
super(props);
this.state = {
};
this._getType = this._getType.bind(this)
}
_getType (wanted) {
const { fbID, fbName, func } = this.props;
let type;
let types = {
'com.xxxx.xx.service.dal.functions.Alarm': function() {
type = <Alarm fbID={fbID} fbName={fbName}/>;
},
'com.xxxx.xxx.service.dal.functions.BooleanControl': function() {
type = <BooleanControl fbID={fbID} fbName={fbName}/>;
},
'com.xxx.xxxx.service.dal.functions.BooleanSensor': function() {
type = <BooleanSensor fbID={fbID} fbName={fbName} />;
},
'com.xxxx.xxx.service.dal.functions.ColorControl': function() {
type = <ColorControl func={func} fbID={fbID} fbName={fbName} />;
}
'default': function() {
type = <WakeUp fbID={fbID} fbName={fbName} />;
}
};
// invoke it
(types[wanted] || types['default'])();
// return a String with chosen type
return type;
}
render() {
const { fbID, fbName, func } = this.props;
const type = this._getType(func.serviceProperties["clazz"]);
return(
<div>
{type}
</div>
)
}
}
// Classes for the different functions.
class ColorControl extends React.Component {
componentWillMount() {
this.props.dispatch(fetchFBEvent(this.props.fbID, "getColor"))
}
constructor(props) {
super(props);
this.state = {
color: {
h: 150.3197479248047,
s: 0.5,
l: 0.5
}
}
this.onChangeComplete = this.onChangeComplete.bind(this);
}
componentWillReceiveProps(nextProps) {
alert("YEP")
// let home = this._getHome(nextProps.areas, nextProps.statics);
// if(home!=null){
// this.setState({
// inputHome: home.name,
// })
// }
}
onChangeComplete(color, event) {
let hsl = color.hsl;
let hue = color.hsl.h/360;
let saturation = color.hsl.s;
let lightness = color.hsl.l;
this.setState({ color: hsl })
// Update props
let fbID = this.props.fbID;
let method = "setColor";
let params = {"hue": hue, "sat": saturation, "light": lightness};
this.props.dispatch(triggerFBEvent(fbID, method, params))
}
_defineFunction(){
}
render() {
return (<div>
<SliderPicker {...this.props}
pointer={ CustomPointer }
color={this.state.color}
onChangeComplete={ this.onChangeComplete }
direction={ 'horizontal' || 'vertical' }/>
</div>
)
}
}
누가 잘못 될지 이해할 수있는 사람이 있습니까?
ColorControl은 (는) redux에 연결되어 있습니까? – Scimonster
'ColorControl'에'connect'를 사용하는 것처럼 보이지 않습니다. 데코레이터 구문을 사용하는 경우에는'ColorControl' 컴포넌트 정의 바로 위에'@ connect'를 추가해야합니다. 물론 연결된 구성 요소의 하위 항목이 아니라면 –