React Native Component Exception - reactjs

I got this error message while working on the other file
Error: Couldn't find a 'component', 'getComponent' or 'children' prop for the screen 'Store'. This can happen if you passed 'undefined'. You likely forgot to export your component from the file it's defined in, or mixed up default import and named import when importing.
my Store file - screen/Store.js:
import React from "react";
import {
StyleSheet,
SafeAreaView,
View,
Text,
TouchableOpacity,
Image,
Animated
} from "react-native";
import { isIphoneX } from 'react-native-iphone-x-helper'
import { icons, COLORS, SIZES, FONTS } from '../constants'
const Store = ({ route, navigation }) => {
...
export default Store;
my Home file - screens/Home.js
import React from "react";
import {
SafeAreaView,
View,
Text,
StyleSheet,
TouchableOpacity,
Image,
FlatList
} from "react-native";
import { icons, images, SIZES, COLORS, FONTS } from '../constants'
const Home = ({ navigation }) => {
...
export default Home;
my navigation file -navigation/tab.js:
import React from 'react';
import {
View,
Image,
TouchableOpacity
} from 'react-native';
import { createBottomTabNavigator, BottomTabBar } from "#react-navigation/bottom-tabs"
import Svg, { Path } from 'react-native-svg';
import { isIphoneX } from 'react-native-iphone-x-helper';
import {Home, User} from '../screens'
import { COLORS, icons } from "../constants"
const Tabs = () => {
...
}
export default Tabs
and my App.js file in the main folder
import React from 'react';
import { createStackNavigator } from "#react-navigation/stack";
import { NavigationContainer } from '#react-navigation/native';
import { Store, OrderDelivery, User } from './screens';
import Tabs from './navigation/tabs';
const Stack = createStackNavigator();
const App = () => {
return (
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerShown: false
}}
initialRouteName={'Home'}
>
<Stack.Screen name="Home" component={Tabs} />
<Stack.Screen name="Store" component={Store} />
<Stack.Screen name="OrderDelivery" component={OrderDelivery} />
<Stack.Screen name="User" component={User} />
</Stack.Navigator>
</NavigationContainer>
)
}
export default App;
I understand what the message means but I dont get what did I do wrong and how to fix it, please help.

Are you sure you imported React in Store.js, try adding the import React from 'react';

Try to import Store from './screens/Store';

Related

Resolve Navigation Error in React Native : Initial Route Name is not working

I am getting this warning and even though the initialRouteName is set to MountedScreen still it open unmountedScreen at start.
Also anywhere I am pressing TouchableOpacity, the screen navigates to next screen.
Warning: Cannot update a component (ForwardRef(BaseNavigationContainer)) while rendering a different component (StateChangeScreen). To locate the bad setState() call inside StateChangeScreen, follow the stack trace as described in https://reactjs.org/link/setstate-in-render
import {NavigationContainer} from '#react-navigation/native';
import {createStackNavigator} from '#react-navigation/stack';
import React from 'react';
import {
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
Text,
useColorScheme,
View,
} from 'react-native';
import MountedScreen from './screens/mounted';
import StateChangeScreen from './screens/stateChange';
import UnmountedScreen from './screens/unMounted';
const Stack = createStackNavigator();
const App = () => {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Mounted">
<Stack.Screen name="Mounted" component={MountedScreen} />
<Stack.Screen name="StateChange" component={StateChangeScreen} />
<Stack.Screen name="Unmounted" component={UnmountedScreen} />
</Stack.Navigator>
</NavigationContainer>
);
};
export default App;

Can't connect Google Analitycs with React.js

how are you doing? I badly cannot connect GA with React, im very stucked and all the videos that i saw the ID connector its start with UA, please help me
import './App.css';
// import Header from "../Header/header"
import Header2 from "../Header2/header"
import Footer from "../Footer/footer"
import Switch from "../Switch/switch"
import {BrowserRouter as Router} from "react-router-dom";
import React, {useEffect} from "react"
import ReactGa from "react-ga";
/**** Icons ****/
import { library } from '#fortawesome/fontawesome-svg-core'
import { fab, faFacebookSquare, faGoogle, faInstagramSquare, faWhatsappSquare} from '#fortawesome/free-brands-svg-icons'
import { fas, faBars, faIdCard, faGlobeAmericas, faCalendarAlt, faArrowUp} from '#fortawesome/free-solid-svg-icons'
library.add(fas, fab, faBars, faFacebookSquare, faInstagramSquare, faWhatsappSquare, faGoogle, faIdCard, faGlobeAmericas, faCalendarAlt, faArrowUp)
function App() {
useEffect(() => {
ReactGa.initialize('G-YZ9S63BMYY')
ReactGa.pageview(window.location.pathname)
}, [])
useEffect(() => {
console.log("hola", window.location.pathname)
})
return (
<Router>
<Header2 />
<React.StrictMode>
<Switch />
</React.StrictMode>
<Footer />
</Router>
);
}
export default App;
From now on thanks for all folks :)
You have to use React for GA4: https://www.npmjs.com/package/react-ga4

React Native: Image is not properly showing

I am running into an issue when trying to display the image. I'm not sure where to go from here. I am importing it correctly and this is a example of a tutorial that I am doing but the author images are displayed but mines are not. What could be the issue? I am following line by line from this tutorial.
ImageScreen.js
import React from "react";
import {View, Text, StyleSheet} from 'react-native';
import ImageDetail from './components/ImageDetail.js';
const ImageScreen = () => {
return (
<><View>
<Text>Hi</Text>
</View><View>
<ImageDetail
title="Forest"
imageSource={require('../../assets/forest.jpg')}
score={9} />
<ImageDetail
title="Beach"
imageSource={require('../../assets/beach.jpg')}
score={7} />
<ImageDetail
title="Mountain"
imageSource={require('../../assets/mountain.jpg')}
score={10} />
</View></>
);
};
const styles = StyleSheet.create({});
export default ImageScreen;
ImageDetail.js
import React from "react";
import {View, Text, StyleSheet, Image} from 'react-native';
const ImageDetail = props => {
return(
<View>
<Image source={props.imageSource}/>
<Text>{props.title}</Text>;
<Text>Image Score - {props.score}</Text>
</View>
);
}
const styles = StyleSheet.create({});
export default ImageDetail;
App.js
import { createAppContainer } from "react-navigation";
import { createStackNavigator } from "react-navigation-stack";
import HomeScreen from "./src/screens/screens/HomeScreen";
import ComponentsScreen from "./src/screens/screens/ComponentsScreen";
import ListScreen from "./src/screens/screens/ListScreen";
import ImageScreen from "./src/screens/ImageScreen";
import CounterScreen from "./src/screens/screens/CounterScreen";
import ColorScreen from "./src/screens/screens/ColorScreen";
import SquareScreen from "./src/screens/screens/SquareScreen";
import TextScreen from "./src/screens/screens/TextScreen";
import BoxScreen from "./src/screens/screens/BoxScreen";
import PhoneCall from "./src/screens/screens/PhoneCall";
import DoctorResults from "./src/screens/DoctorResults";
const navigator = createStackNavigator(
{
Home: HomeScreen,
Components: ComponentsScreen,
List: ListScreen,
Image: ImageScreen,
Counter: CounterScreen,
Color: ColorScreen,
Square: SquareScreen,
Text: TextScreen,
Box: BoxScreen,
Phone: PhoneCall,
Doctor: DoctorResults,
},
{
initialRouteName: "Home",
defaultNavigationOptions: {
title: "App",
},
}
);
export default createAppContainer(navigator);
Here's the results but I don't get any image to appear
You can try giving some width and height to the image component like
<Image
style={{width: 50, height: 50}} //or 100%
source={require("dir")} // Make sure image dir is correct
/>
Hope it will help solve your problem.
Please check your image directory is correct or not.
Ctrl+Click to your image assets directory.
If image can open, it is correct route. If not, you need to check your image directory again.
imageSource={(require('../../assets/image.png'))}
I try with your code and show like this. I think problem is with your image and image directory.
Please try to add width and height in image.
<View>
<Image style={{width: 100, height: 100}} source= {props.imageSource} />
<Text>{props.title}</Text>
<Text>Image Score - {props.score}</Text>
</View>

Updating syntax for AppNavigator in react-native app using react-navigation v5

In my react-native app I am in the process of upgrading to react-navigation v5. For AppNavigator, which is passed into my main App.js file, the old code looks like this:
import { createAppContainer, createSwitchNavigator, createStackNavigator } from 'react-navigation';
import LoginScreen from '../screens/LoginScreen';
import LoadingScreen from '../screens/LoadingScreen';
const AuthStack = createStackNavigator({
Login: LoginScreen,
Loading: LoadingScreen
});
import MainDrawerNavigator from './DrawerNavigator';
export default createAppContainer(createSwitchNavigator({
Main: MainDrawerNavigator,
Auth: AuthStack
},
{
initialRouteName: 'Auth',
}));
The code gets used in App.js like so:
<Provider store={store}>
<NavigationContainer ref={navigationRef}>
<View style={styles.container}>
{Platform.OS === 'ios' && <StatusBar barStyle="light-content" />}
<AppNavigator ref={nav => { navigatorRef = nav }} /> // AppNavigator used here
</View>
</NavigationContainer>
</Provider>
From what I can tell, createAppContainer is no longer the way to handle this in react-navigation v5. I'm getting an error on this import specifically:
import { createAppContainer, createSwitchNavigator, createStackNavigator } from 'react-navigation';
... partly because the directory structure for the location of these kinds of imports has changed. But from what I can tell, createAppContainer is not existent now? In other words, it's not just an issue of it being located somewhere else now. Correct me if I'm wrong.
So my question is, what should this code look like in v5? Any insight would be appreciated. I'm referring to this AppNavigator code:
import { createAppContainer, createSwitchNavigator, createStackNavigator } from 'react-navigation';
import LoginScreen from '../screens/LoginScreen';
import LoadingScreen from '../screens/LoadingScreen';
const AuthStack = createStackNavigator({
Login: LoginScreen,
Loading: LoadingScreen
});
import MainDrawerNavigator from './DrawerNavigator';
export default createAppContainer(createSwitchNavigator({
Main: MainDrawerNavigator,
Auth: AuthStack
},
{
initialRouteName: 'Auth',
}));
Firstly first you need import NavigationContainer to contain all of your navigations
import { NavigationContainer } from '#react-navigation/native'
then after that create your StackNavigator like this
import { createStackNavigator } from '#react-navigation/stack'
const Stack = createStackNavigator()
import LoginScreen from '../screens/LoginScreen'
import LoadingScreen from '../screens/LoadingScreen'
function AuthStack() {
return (
<Stack.Navigator>
<Stack.Screen
name = "LoginScreen"
component = {LoginScreen}
/>
<Stack.Screen
name = "LoadingScreen"
component = {LoadingScreen}
/>
</Stack.Navigator>
)
}
next, create the drawer navigator
import { createDrawerNavigator } from '#react-navigation/drawer'
const MainDrawer = createDrawerNavigator()
finally the App function will looks like this
import { NavigationContainer } from '#react-navigation/native'
import { createStackNavigator } from '#react-navigation/stack'
import { createDrawerNavigator } from '#react-navigation/drawer'
const Stack = createStackNavigator()
import LoginScreen from '../screens/LoginScreen'
import LoadingScreen from '../screens/LoadingScreen'
function AuthStack() {
return (
<Stack.Navigator>
<Stack.Screen
name = "LoginScreen"
component = {LoginScreen}
/>
<Stack.Screen
name = "LoadingScreen"
component = {LoadingScreen}
/>
</Stack.Navigator>
)
}
const MainDrawer = createDrawerNavigator()
export default function App() {
return (
<NavigationContainer>
<MainDrawer.Navigator
initialRouteName = "Auth"
>
<MainDrawer.Screen
name = 'Auth'
component = {AuthStack}
/>
<MainDrawer.Screen
name = 'YourDrawerScreen'
component = {YourDrawerScreen}
/>
</MainDrawer.Navigator>
</NavigationContainer>
)
}
I don't think there is Switch Navigator in React-Navigation v5

(React) How to send variable value to other component?

It's a nice day.
//App.js
import React, { useEffect, useRef, useState, createContext, useContext } from "react"
import {
StyleSheet, StatusBar, View, Text, Linking, Button,
SafeAreaView, TouchableOpacity, RefreshControl } from 'react-native';
export default function App() {
const wannaConst = 'qwqw'
return (
<View>
<Text>
Good Good
</Text>
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center'
}
})
//screens > Home > Home.js
import React from 'react'
import { View, Text } from 'react-native'
const Home = () => {
return (
<View>
<Text>{wannaConst}</Text>
</View>
)
}
export default Home
I wanna use App.js's wannaConst's Variable Value
at screens > Home > Home.js
if wannaConst = 'qrqr',
Home components return [qrqr] screens.
or wannaConst = 'help me :(',
Home components return [help me :(] screens...
and so on.
How to solve it? use Redux? or ContextAPI?
Thx for reading.
Both way will work OK. If your project is small or middle-sized, context API will work without any problem.
AppContext.jsx
import {createContext} from 'react';
export default createContext({
wannaConst: 'qwqw'
}); // provide initial value
App.jsx
import React, { useEffect, useRef, useState, createContext, useContext, useCallback } from "react"
import {
StyleSheet, StatusBar, View, Text, Linking, Button,
SafeAreaView, TouchableOpacity, RefreshControl } from 'react-native';
import AppContext from './AppContext'
export default function App() {
// You can manage AppContext state here
const [contextValue, setContextValue] = useState({
wannaConst: 'qrqr' // provide initial value here, default value in AppContext.jsx will be overwritten
}};
// context values are also React states. You can update the state like any other React states
const handlePressButton = useCallback(
() => setContextValue({wannaConst: 'good good'}),
[]);
return (
<AppContext.Provider value={contextValue}>
<View>
<Text>
Good Good
</Text>
<Button onPress={handlePressButton}>
Change context to 'good good'
</Button>
</View>
//... child components that are going to consume AppContext value
</AppContext.Provider>
)
}
Be aware that screens/Home/Home.js should be nested inside AppContext.Provider. Most of the case, it will be like so, because you will create stack/tab navigations and list all the navigation routes and screens under App.jsx.
Home.jsx
import React, {useContext} from 'react'
import { View, Text } from 'react-native'
import AppContext from './AppContext';
const Home = () => {
const appContext = useContext(AppContext);
return (
<View>
<Text>{appContext.wannaConst}</Text>
</View>
)
}
export default Home
Using redux is somewhat difficult but it is almost mandatory in enterprise apps. Here you can find a good source for modern react and redux

Resources