【发布时间】:2020-08-25 20:59:02
【问题描述】:
我正在尝试将 ref 从父级传递给其子级。 child是一个函数组件,所以我在做:
// Child
const Configuration = forwardRef((props, ref) => {
const { colors } = useTheme();
const fall = useRef(new Animated.Value(1)).current;
return <></>
});
一切运行良好。但是当我尝试这样做时
export default withFirebase(Configuration);
问题出现了……
这里是 HOC 组件:
import React from "react";
import { FirebaseContext } from "../Firebase/";
const withFirebase = (Component) => (props) => (
<FirebaseContext.Consumer>
{(firebase) => <Component {...props} firebase={firebase} />}
</FirebaseContext.Consumer>
);
export default withFirebase;
任何想法如何将 ref 传递给包装在 HOC 上的功能组件?
我尝试过这样做:
const Configuration = forwardRef((props, ref) => withFirebase(() => {
const { colors } = useTheme();
const fall = useRef(new Animated.Value(1)).current;
return <></>
}));
export default Configuration;
但是没有用。谢谢。
【问题讨论】:
标签: javascript reactjs react-native expo