1
1
mirror of https://github.com/jxnblk/mdx-deck.git synced 2024-11-10 14:21:06 +03:00

Prevent Appear from resetting when changing slides

This commit is contained in:
Trevor Burnham 2019-02-18 19:32:37 -05:00
parent 346112de6a
commit 58db2a6a43

View File

@ -11,10 +11,21 @@ export default withDeck(
deck: PropTypes.object.isRequired,
}
static getDerivedStateFromProps(props) {
const { deck } = props
if (!deck.active) return null
return {
step: deck.step,
}
}
constructor(props) {
super(props)
const { update, index } = props.deck
const steps = React.Children.toArray(props.children).length
this.state = {
step: 0,
}
update(setSteps(index, steps))
}
@ -22,7 +33,7 @@ export default withDeck(
const children = React.Children.toArray(this.props.children).map(child =>
typeof child === 'string' ? <div>{child}</div> : child
)
const { step, mode } = this.props.deck
const { mode } = this.props.deck
if (mode === modes.grid) {
return children
@ -35,6 +46,8 @@ export default withDeck(
return children
}
const { step } = this.state
return (
<React.Fragment>
{children.map((child, i) =>