Open dengshasha opened 6 years ago
I have same issue, but unfortunately, previous code didn't help.
@dropsydice I'm sorry, I forget to specify which file I modified. when I refresh this page: and I modify SectionsContainer.js:
constructor(props) {
super(props);
this.state = {
activeSection: props.activeSection,
scrollingStarted: false,
sectionScrolledPosition: 0,
windowHeight: window.innerHeight //modify 0 to window.innerHeight
};
I refresh again: would you try again?
My way of fixing it is calling this method:
componentDidUpdate () {
setTimeout(this.refs.container._handleResize , 1);
}
It's scroll to URL anchor when the viewport resizes
It's a good idea!@dropsydice
Is there a proper fix for this.
Hey,
The cleanest way I found is too pass a activeSection prop to the SectionContainer and update it with the scrollCallback the first time it's set.
class Cmp extends React {
constructor() {
super();
this.state = {
initialActiveSection: null
};
}
onScroll(p) {
if (this.state.initialActiveSection === null)
this.setState(() => ({ initialActiveSection: p.activeSection }));
}
render() {
const { initialActiveSection } = this.state;
return (
<SectionsContainer
{...options}
activeSection={initialActiveSection}
scrollCallback={this.onScroll}
/>
);
}
}
Maybe this can solve : SectionsContainer.js: