मैं निर्माता विधि के संबंध में React Docs पढ़ लिया है और क्या यह जहाँ तक राज्य की स्थापना और कार्यों बंधन के रूप में इस्तेमाल किया जा सकता है, लेकिन यह वास्तव में ज्यादातर मामलों में आवश्यक है?निर्माता विधि में प्रतिक्रिया
export default class MyClass extends Component {
constructor(props) {
super(props);
this.state = {
foo: 'bar',
};
this.member = 'member';
this.someFunction = this.anotherFunction(num);
}
anotherFunction = (num) => num * 2;
render() {
// render jsx here
}
}
कर और केवल एक ही विकल्प अन्य से अधिक पसंद है
export default class MyClass extends Component {
state = {
foo: 'bar',
};
member = 'member';
someFunction = this.anotherFunction(num);
anotherFunction = (num) => num * 2;
render() {
// render jsx here
}
}
की तरह निर्माता के बाहर यह सब डाल और वहाँ किसी भी प्रदर्शन के मुद्दों के बारे में मैं जानना चाहिए के बीच क्या अंतर है? यह मुझे थोड़ी देर के लिए परेशान कर रहा है और मुझे वहां एक ठोस जवाब नहीं मिल रहा है।
'foo = bar' वाक्य रचना * बाहर * निर्माता नहीं मान्य JavaScript, यह एक प्रायोगिक सुविधा है। –