Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

preact-motion does not work with Preact X due to the change in this.props.children not always being an array #4

Open
CragVFX opened this issue Apr 26, 2020 · 0 comments

Comments

@CragVFX
Copy link

CragVFX commented Apr 26, 2020

this.props.children is not guaranteed to be an array and the preact-motion library relies on it being an array.

reference: https://preactjs.com/guide/v10/upgrade-guide/#propschildren-is-not-always-an-array

Error when switching to Preact X:

TypeError: this.props.children[0] is not a function

to fix this, use the toChildArray method from preact in the following functions:

Motion.prototype.render = function render() { var children = preact.toChildArray(this.props.children); return children[0](this.state.currentStyle); };

StaggeredMotion.prototype.render = function render() { var children = preact.toChildArray(this.props.children); return children[0](this.state.currentStyles); };

TransitionMotion.prototype.render = function render() { var hydratedStyles = rehydrateStyles(this.state.mergedPropsStyles, this.unreadPropStyles, this.state.currentStyles); var children = preact.toChildArray(this.props.children); return children[0](hydratedStyles); };

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant