से अधिक हो गया है मैं प्रतिक्रिया में काम कर रहा हूं और मूल रूप से मैं टूलटिप के साथ एक बटन बनाना चाहता हूं, अभी मैं टूलटिप बना रहा हूं। मैं सीएसएस डिस्प्ले प्रॉपर्टी को बदल रहा हूं ताकि माउस को दर्ज करने और छोड़ने के दौरान इसे दृश्यमान बनाया जा सके या नहीं। लेकिन वहाँ एक त्रुटि है और मैं क्या करना है पता नहीं है ...प्रतिक्रिया, अनकही रेंज त्रुटि: अधिकतम कॉल स्टैक आकार
यहाँ मेरी कोड है:
Uncaught RangeError: Maximum call stack size exceeded
at defineRefPropWarningGetter (App.js:1053)
at Object.ReactElement.createElement (App.js:1220)
at Object.createElement (App.js:3329)
at Constructor.render (App.js:43403)
at App.js:15952
at measureLifeCyclePerf (App.js:15233)
at ReactCompositeComponentWrapper._renderValidatedComponentWithoutOwnerOrContext (App.js:15951)
at ReactCompositeComponentWrapper._renderValidatedComponent (App.js:15978)
at ReactCompositeComponentWrapper._updateRenderedComponent (App.js:15902)
at ReactCompositeComponentWrapper._performComponentUpdate (App.js:15880)
मैं:
import React from 'react';
import ReactDOM from 'react-dom';
import Style from 'style-it';
var Ink = require('react-ink');
import FontIcon from '../FontIcon/FontIcon';
var IconButton = React.createClass({
getInitialState() {
return {
iconStyle: "",
style: "",
cursorPos: {},
};
},
extend(obj, src) {
Object.keys(src).forEach(function(key) { obj[key] = src[key]; });
return obj;
},
Tooltip(props) {
var style = {};
if (this.tooltipDisplay) {
style.display = "block";
} else if (!this.tooltipDisplay) {
style.display = "none";
};
return <div className="tooltip" style={style}>{_props.tooltip}</div>;
},
showTooltip(){
this.tooltipDisplay = true;
},
removeTooltip(){
this.tooltipDisplay = false;
},
render() {
var _props = this.props,
tooltip = this.Tooltip,
opts,
tooltipDisplay = false,
disabled = false,
rippleOpacity,
outterStyleMy = {
border: "none",
outline: "none",
padding: "8px 10px",
"background-color": "red",
"border-radius": 100 + "%",
cursor: "pointer",
},
iconStyleMy = {
"font-size": 12 + "px",
"text-decoration": "none",
"text-align": "center",
display: 'flex',
'justify-content': 'center',
'align-items': 'center',
},
rippleStyle = {
color: "rgba(0,0,0,0.5)",
};
if (_props.disabled || _props.disableTouchRipple) {
rippleStyle.opacity = 0;
};
this.setState({
iconStyle: _props.iconStyle
});
this.setState({
style: _props.style
});
if (_props.disabled) {
disabled = true;
};
if (this.state.labelStyle) {
iconStyleMy = this.state.iconStyle;
};
if (this.state.style) {
outterStyleMy = this.state.style;
};
if (_props.href) {
opts.href = _props.href;
};
var buttonStyle = this.extend(outterStyleMy, iconStyleMy);
return(
<Style>
{`
.IconButton{
position: relative;
}
.IconButton:disabled{
color: ${_props.disabledColor};
}
.btnhref{
text-decoration: none;
}
`}
<a {...opts} className="btnhref" >
<tooltip text={this.props.tooltip} position={this.options} />
<button ref="button" className={"IconButton" + _props.className} disabled={disabled} style={buttonStyle}
onMouseEnter={this.showTooltip} onMouseLeave={this.removeTooltip} >
<Ink background={true} style={rippleStyle} opacity={rippleOpacity} />
<FontIcon className={_props.iconClassName}/>
</button>
</a>
</Style>
);
}
});
ReactDOM.render(
<IconButton href="" className="" iconStyle="" style="" iconClassName="face" disabled="" disableTouchRipple="" tooltip="aaaaa" />,
document.getElementById('app')
);
कंसोल में मैं इस त्रुटि मिल रही है क्या गलत है पता नहीं कर सकता। मुझे पता है कि यह एक फ़ंक्शन को कॉल करने के बारे में कुछ हो सकता है जो बदले में एक और फ़ंक्शन कॉल करता है। लेकिन मैं अपने कोड में ऐसा कुछ नहीं देख सकता हूं और मुझे यकीन नहीं है कि यह सब कुछ है या नहीं। मदद :)
कभी नहीं, कभी, किसी भी परिस्थिति में ... मुझे परवाह नहीं है क्या आप तर्क के लिए के लिए आ सकता है ... कभी अपने 'render' समारोह अंदर से' setState' कॉल नहीं करते ;) 'सेटस्टेट' को कॉल करने से पुनर्वितरण होता है, जो 'सेटस्टेट' को कॉल करने का कारण बनता है जो एक पुनर्विक्रय का कारण बनता है, जो तब 'सेटस्टेट' कहता है और इस प्रकार एक पुनर्वितरण का कारण बनता है, जो तब 'सेटस्टेट' को अभी तक agian कहते हैं, और आपके घटक को फिर से प्रस्तुत किया जाता है, फिर 'सेटस्टेट' को दोबारा बुलाया जाता है और दूसरा पुन: प्रस्तुत किया जाता है ... जब तक कि आपका कॉल स्टैक अधिकतम नहीं हो जाता है –
@RyanWheale मेरी इच्छा है कि मैं उस टिप्पणी को दस लाख बार ऊपर उठा सकूं :) – Icepickle
धन्यवाद, यह समझ में आता है, मैंने नहीं सोचा कि – Karol