【发布时间】:2019-12-13 00:34:52
【问题描述】:
如果您尝试将功能性(非反应类)组件传递给Animated.createAnimatedComponent,它会抛出一个错误提示
无状态功能组件作为 createAnimatedComponent 的子级无效
来自一个使用反应钩子的应用程序,基本上我的所有组件都可以正常工作。
有没有一种方法/助手可以允许将这些传递给 createAnimatedComponent 而无需将它们包装在 Animated.View 甚至只是 View 中?
这是我想要制作动画的组件示例
function MyComponent({ someProp }) {
const [counter, setCounter] = useState(0);
return (
<View>
<Text>{counter}</Text>
</View>
);
}
【问题讨论】:
-
useState(0)是什么? -
@hongdevelop React Hooks.
-
@hongdevelop 这里有更多关于钩子的信息reactjs.org/docs/hooks-intro.html
-
只从 React 函数组件调用 Hooks。不要从常规 JavaScript 函数中调用 Hooks。 (只有另一个有效的地方可以调用 Hooks——你自己的自定义 Hooks。
-
他们说你必须自己做 Hooks。
标签: reactjs react-native react-hooks