Im trying to render react native component as function return, without sucesses, here is the code:
// In App.js in a new project
import * as React from 'react';
import { View, Text, TouchableOpacity, Linking, Alert } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import * as Google from 'expo-auth-session/providers/google';
import * as WebBrowser from 'expo-web-browser';
import { FacebookSocialButton, GoogleSocialButton } from "react-native-social-buttons";
import { AuthRequest, useAuthRequest } from 'expo-auth-session';
class MainClass extends React.Component {
constructor(props) {
super(props);
this.state = {
}
WebBrowser.maybeCompleteAuthSession();
Stack = createStackNavigator();
() => App(() => renderRoutes());
}
setResponse = (response) => {
this.setState({response:response}).then(Alert.alert(this.state.response));
}
LoginGoogle = () => {
const [request, response, promptAsync] = Google.useAuthRequest({
androidClientId: 'xxxxxxx.apps.googleusercontent.com',
expoClientId: 'xxxxxxxx.apps.googleusercontent.com'
});
React.useEffect(() => {
if (response?.type === 'success') {
const { authentication } = response;
}
}, [response]);
return (
<GoogleSocialButton disabled={!request} onPress={() => {promptAsync().then(() => {const [request, response, promptAsync] = useAuthRequest({}, {setResponse(response){}})})}} />
)
}
LoginScreen = (LoginGoogle) => {
const nav = this.props.navigation;
return (
<View style={{ flex: 1, backgroundColor: "#a2eff5"}}>
<View style={{flex: 0.15}}></View>
<View style={{flex: 0.1, backgroundColor: "white", borderRadius: 100/2, alignItems: "center", justifyContent: "center"}}>
<Text style={{color: "black"}}>Please, Login using buttons below!</Text>
</View>
<View style={{flex: 0.2}}></View>
<View style={{alignItems:"center", justifyContent: "center"}}>
{LoginGoogle()}
</View>
<View style={{flex: 0.05}}></View>
<View style={{alignItems:"center", justifyContent: "center"}}>
<FacebookSocialButton onPress={() => {}} />
</View>
</View>
);
}
MainScreen = () => {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home Screen</Text>
</View>
);
}
renderRoutes = () => {
return (
<NavigationContainer>
<Stack.Navigator
initialRouteName={"Login"}
screenOptions={{headerShown: false}}>
<Stack.Screen name="Login" component={LoginScreen} />
<Stack.Screen name="Main" component={MainScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
}
App = (RenderComponent) => {
return (
{RenderComponent}
);
}
export default App;
And here is the error im getting: Objects are not valid as React child (found: object with keys {RenderComponent}) If you meant to render a collection of children, use an array instead
Anyone know how this should be done?
RenderComponentcome from? what does it do?Appand removeMainClass. if you're going to use hooks here, stick with that style while you're learning{RenderComponent}. you probably want<>{RenderComponent}</>at the very least. beyond that it's almost certainly a function so it would be<RenderComponent />or<>{RenderComponent()}</>