есть класс
export class IconStar extends React.Component{
constructor(props) {
super(props);
this.state = {
active: this.props.fix,
fill: svgicons.starIcon.deactiv,
class: 'transparent'
}
this.fix_it = this.fix_it.bind(this);
console.log(this.props.fix)
}
fix_it(e){
if (this.state.active == false){
this.setState({
active: true,
fill: svgicons.starIcon.active,
}).bind(fixation);
}
if (this.state.active == true){
this.setState({
fill: svgicons.starIcon.deactiv,
active: false,
});
}
var css = (this.state.class === "transparent") ? "show" : "transparent";
this.setState({"class":css});
}
render(){
return(
<div>
<svg
className={"star_icon" + " " + this.state.class}
xmlns="http://www.w3.org/2000/svg"
aria-labelledby="title"
onClick={this.props.fixation}
>
<title id="title">Нажмите, чтобы закрепить вверху списка</title>
<path d= {this.state.fill}
/>
</svg>
</div>
)
}
}
Как можно на onClick повесить вызов функции? нашел только способ через props {this.props.fixation}
Как Можно вызвать из функции fix_it(e), к примеру
? (на он клик вешаем {this.fix_it}), а из fix_it уже вызываем fixation.
Как можно передать state компонента в store
?
компонент в котором fixation и куда нужно обращаться
export let IconStarController = connect(
state => ({
fix : state.controlR.fix,
}),
dispatch => bindActionCreators({
fixation(){
return function(dispatch, getState){
let state = store.getState();
if (state.controlR.fix === false) {
console.log("таки no!")
dispatch({
type : 'FIX_IT',
fix : true,
})
}
else if (state.controlR.fix === true) {
console.log("таки Yes!")
dispatch({
type : 'FIX_IT',
fix : false,
})
}
}
},
}, dispatch)
)(IconStar)
почему у меня при таком объявлении значение fix получается props
? storage8.static.itmages.com/i/17/0216/h_1487254091...
как сделать state
?