Closed bobmulder closed 6 years ago
Thanks for the addition. This makes more sense now!
@bobmulder Hey I realized a better way to handle initial scrollToIndex
. ParallaxSwiper.js
needs to call scrollToIndex()
in componentDidMount()
if it exists.
Like:
componentDidMount() {
const { scrollToIndex } = this.props;
if (scrollToIndex) {
this.scrollToIndex(scrollToIndex);
}
}
This way you can just pass state
and it will scroll to the index specified in initial state on mount. Can you implement this? Then I can merge the PR. 👍
Am I right this is done now via componentWillReceiveProps
at ParallaxSwiper.js
and you want to move it to componentDidMount
?
We want to have it in both places. So it scrolls to the index specified in user’s initial state on component mount and then works when they update it.
In this snippet, ParallaxSwiper
will scroll to index 3 when it first mounts via componentDidMount
. Then anytime this.state.index
is changed it will update via componentWillReceiveProps
.
state = { index: 3 }
...
<ParallaxSwiper scrollToIndex={this.state.index}>
...
</ParallaxSwiper>
Ahh got it! I'll create a PR to discuss this code. Your code suggestion looks fine to me?
@bobmulder Updated your change to include that it needs to be state and fixed a typo. Does this description make sense to you now?