मैं वर्तमान में प्रतिक्रिया सीखने के लिए एक ड्रॉपडाउन बटन बना रहा हूं। मैंने माता-पिता div में दो mouseEnter और onMouseLeave ईवेंट बनाये हैं, जब यह होवर हो रहा है तो इसे गायब होने पर दिखाई नहीं दे रहा है। समस्या यह है कि वे घटनाएं केवल माता-पिता के साथ रहती हैं।पर हमला करने के लिए कैसे रहें बच्चे के संदर्भ में शामिल हैं?
रिमोट पर मॉउसलिव को कैसे बनाया जाए बच्चे के संदर्भ में शामिल हैं? या, बच्चों पर होवर करते समय मैं राज्य का विस्तार कैसे सच रख सकता हूं?
class DropDownButton extends React.Component {
constructor(){
super();
this.handleHoverOn = this.handleHoverOn.bind(this);
this.handleHoverOff = this.handleHoverOff.bind(this);
this.state = {expand: false};
}
handleHoverOn(){
if(this.props.hover){
this.setState({expand: true});
}
}
handleHoverOff(){
if(this.props.hover){
this.setState({expand: false});
}
}
render() {
return (
<div>
<div className={styles.listTitle}
onMouseEnter={this.handleHoverOn}
onMouseLeave={this.handleHoverOff}>
{this.props.name}
</div>
<div>
{React.Children.map(this.props.children, function(child){
return React.cloneElement(child, {className: 'child'});
})}
</div>
</div>
);
}
}
यह काम करता है। मैंने एक बेवकूफ गलती की, और सशर्त प्रतिपादन भी मेरे लिए उपयोगी है। धन्यवाद! –