我在我的反應應用程序中使用open source scrollbar component。擴展反應組件的問題/問題
import PropTypes from "prop-types";
import Scrollbars from "react-custom-scrollbars";
// This component extends react-custom-scrollbars and allows
// the developer to force an update of the scrollbars
// every 'X' ms.
class ForcedScrollbars extends Scrollbars {
componentDidMount() {
this.rerenderTimer = setInterval(() => {
this.update();
}, this.props.forceRerenderTimer);
}
componentWillUnmount() {
clearInterval(this.rerenderTimer);
}
}
ForcedScrollbars.propTypes = {
forceRerenderTimer: PropTypes.number
};
export default ForcedScrollbars;
我有兩個問題:
,使其看起來像這樣我已經延長了組件。
在父組件
Scrollbars
的componentDidMount
方法是這樣的:componentDidMount() { this.addListeners(); this.update(); this.componentDidMountUniversal(); }
在我ForcedScrollbars
組件將同樣的方法被調用在ForcedScrollbars
componentDidMount
來電或我打電話他們再次明確?即
class ForcedScrollbars extends Scrollbars {
componentDidMount() {
this.addListeners();
this.update();
this.componentDidMountUniversal();
this.rerenderTimer = setInterval(() => {
this.update();
}, this.props.forceRerenderTimer);
}
// REST OF COMPONENT //
- 我看到的誤差在控制檯
警告:標籤未知丙forceRerenderTimer。從元素中刪除這個 道具。有關詳細信息,請參閱...(臉書鏈接)...
正如你可以在我的代碼中看到上面我有以下看起來不工作。
ForcedScrollbars.propTypes = {
forceRerenderTimer: PropTypes.number
};
此外,我試過哪些也沒有出現工作。
Scrollbars.propTypes = {
forceRerenderTimer: PropTypes.number
};
檢查codesandbox在這裏。
添加'contructor'與調用'超(道具)'。 – Dez