Skip to content

Instantly share code, notes, and snippets.

@RayLuxembourg
Last active May 21, 2019 08:26
Show Gist options
  • Save RayLuxembourg/e547adadcd646efd29eeae202a233d0c to your computer and use it in GitHub Desktop.
Save RayLuxembourg/e547adadcd646efd29eeae202a233d0c to your computer and use it in GitHub Desktop.
bind argument without effecting this
class PoseSwiper extends Component<Props> {
state = {
activeIndex: 0
};
config = {
slidesPerView: 1,
observer: true,
on: {
slideChange: function(applyNewIndex: (index: number) => void) {
applyNewIndex(this.activeIndex);
}
}
};
constructor(props) {
super(props);
const method = this.config.on.slideChange;
const onIndexChange = this.setIndex;
this.config.on.slideChange = function() {
method.bind(this, onIndexChange)();
};
}
setIndex = (index: number) => {
this.setState((prev) => ({ ...prev, activeIndex: index }));
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment