রিঅ্যাক্ট.জেজে, একটি টাইমআউট রেফারেন্সকে উদাহরণ ভেরিয়েবল (এটি.টাইমআউট) বা স্টেট ভেরিয়েবল (this.state.Toutout) হিসাবে সংরক্ষণ করা কি ভাল?
React.createClass({
handleEnter: function () {
// Open a new one after a delay
var self = this;
this.timeout = setTimeout(function () {
self.openWidget();
}, DELAY);
},
handleLeave: function () {
// Clear the timeout for opening the widget
clearTimeout(this.timeout);
}
...
})
অথবা
React.createClass({
handleEnter: function () {
// Open a new one after a delay
var self = this;
this.state.timeout = setTimeout(function () {
self.openWidget();
}, DELAY);
},
handleLeave: function () {
// Clear the timeout for opening the widget
clearTimeout(this.state.timeout);
}
...
})
এই উভয় পদ্ধতির কাজ। আমি কেবল একে অপরকে ব্যবহার করার কারণগুলি জানতে চাই।
টিপ: প্রতিক্রিয়াটির স্বাবলম্বনটি ব্যবহার করুন:
—
ডেভিড হেলসিং
this.timeout = setTimeout(this.openWidget, DELAY);
ডিলে কী সেট করা উচিত?
—
justingordon
this.stateসরাসরি আহ্বানের মত গণ্য করোsetState()পরে পরিব্যক্তি প্রতিস্থাপন করতে পারি তোমার সাথে আচরণ করেছেন।this.stateযেমন যদি এটা অপরিবর্তনীয় ছিল।"