Skip to content

Commit 2df98e9

Browse files
authored
Merge pull request #253 from TrevorBurnham/appear-preserve-steps-while-inactive
Prevent Appear from resetting when changing slides
2 parents 91df30b + 58db2a6 commit 2df98e9

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/Appear.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,29 @@ export default withDeck(
1111
deck: PropTypes.object.isRequired,
1212
}
1313

14+
static getDerivedStateFromProps(props) {
15+
const { deck } = props
16+
if (!deck.active) return null
17+
return {
18+
step: deck.step,
19+
}
20+
}
21+
1422
constructor(props) {
1523
super(props)
1624
const { update, index } = props.deck
1725
const steps = React.Children.toArray(props.children).length
26+
this.state = {
27+
step: 0,
28+
}
1829
update(setSteps(index, steps))
1930
}
2031

2132
render() {
22-
const children = React.Children.toArray(this.props.children).map(
23-
child => (typeof child === 'string' ? <div>{child}</div> : child)
33+
const children = React.Children.toArray(this.props.children).map(child =>
34+
typeof child === 'string' ? <div>{child}</div> : child
2435
)
25-
const { step, mode } = this.props.deck
36+
const { mode } = this.props.deck
2637

2738
if (mode === modes.grid) {
2839
return children
@@ -35,6 +46,8 @@ export default withDeck(
3546
return children
3647
}
3748

49+
const { step } = this.state
50+
3851
return (
3952
<React.Fragment>
4053
{children.map((child, i) =>

0 commit comments

Comments
 (0)