我在我的反应应用程序中使用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