Skip to content

Commit

Permalink
Merge pull request #1272 from randallreedjr/before-change-current-slide
Browse files Browse the repository at this point in the history
Before change current slide
  • Loading branch information
akiran committed Oct 20, 2018
2 parents 5d3c110 + d0ab671 commit cad14fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion examples/SlideChangeHooks.js
Expand Up @@ -3,6 +3,7 @@ import Slider from "../src/slider";

export default class SlideChangeHooks extends Component {
state = {
oldSlide: 0,
activeSlide: 0,
activeSlide2: 0
};
Expand All @@ -13,12 +14,16 @@ export default class SlideChangeHooks extends Component {
speed: 1000,
slidesToShow: 1,
slidesToScroll: 1,
beforeChange: (current, next) => this.setState({ activeSlide: next }),
beforeChange: (current, next) =>
this.setState({ oldSlide: current, activeSlide: next }),
afterChange: current => this.setState({ activeSlide2: current })
};
return (
<div>
<h2>beforeChange and afterChange hooks</h2>
<p>
BeforeChange => oldSlide: <strong>{this.state.oldSlide}</strong>
</p>
<p>
BeforeChange => activeSlide: <strong>{this.state.activeSlide}</strong>
</p>
Expand Down
3 changes: 2 additions & 1 deletion src/inner-slider.js
Expand Up @@ -369,12 +369,13 @@ export class InnerSlider extends React.Component {
slideHandler = (index, dontAnimate = false) => {
const {
asNavFor,
currentSlide,
beforeChange,
onLazyLoad,
speed,
afterChange
} = this.props;
// capture currentslide before state is updated
const currentSlide = this.state.currentSlide;
let { state, nextState } = slideHandler({
index,
...this.props,
Expand Down

0 comments on commit cad14fc

Please sign in to comment.