如何将这个孩子包装在高阶组件中?

问题描述 投票:0回答:1
const LoggedInView = (props) => <Text>You are logged in!</Text>
export default withAuth(LoggedInView)


const withAuth = (component) => <AuthRequired>{ component }</AuthRequired>


const AuthRequired = (props) => {
    const context = useContext(AuthContext)
    if(!context.auth){
        return (
            <View style={styles.container}>
               <Text>You need to login . Click here</Text>
            </View>
        )
    }
    return props.children 
}

我的<AuthRequired>视图工作正常,但我的withAuth无效。

reactjs react-native higher-order-components
1个回答
0
投票

据我所知,您不能在React中以子代形式返回函数。您如何尝试呢?

© www.soinside.com 2019 - 2024. All rights reserved.