【发布时间】:2019-12-28 23:44:03
【问题描述】:
我确信这与我不完全了解 React Spring 的工作原理或 HOC 的原理有关。
我正在尝试为 React 创建一个 HOC,添加一个 React Spring 动画(从左侧滑入子组件)
const SlideLeft = WrappedComponent => {
const [props] = useSpring({
translateX: "0",
from: { translateX: "1000vw" }
});
return (
<animated.div style={props}>
<WrappedComponent />
</animated.div>
);
};
然后,在另一个组件中,我有这个:
<SlideLeft>
<Categories />
</SlideLeft>
我认为这会起作用,但我得到了错误:
TypeError: arr[Symbol.iterator] is not a function
我发现这个页面建议将其更改为 const props:
https://github.com/react-spring/react-spring/issues/616
但是,当我这样做时,我得到了错误:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Check the render method of `SlideLeft`.
所以我不太确定如何让 HOC 与 React Spring 一起工作。
任何信息都会很有启发性。
【问题讨论】:
标签: reactjs react-hooks react-spring