Expo simple Webview, Error: Element type is invalid - react-native

I am new to react native and trying to implement this simple webview from Expo docs:
https://docs.expo.dev/versions/latest/sdk/webview/
This is all I am doing and there is not much more to it.
import * as React from 'react';
import { WebView } from 'react-native-webview';
import { StyleSheet } from 'react-native';
import Constants from 'expo-constants';
export default function App() {
return (
<WebView
style={styles.container}
source={{ uri: 'https://google.com' }}
/>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: Constants.statusBarHeight,
},
});
my Package.json looks like this:
"dependencies": {
"expo": "~45.0.0",
"expo-constants": "~13.1.1",
"expo-status-bar": "~1.3.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-native": "0.68.2",
"react-native-webview": "11.18.1"
},
But when I run expo start, I get this error on ios simulator:
ERROR Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check the render method of `App`.
This error is located at:
in App (created by ExpoRoot)
in ExpoRoot
in RCTView (created by View)
in View (created by AppContainer)
in DevAppContainer (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in main(RootComponent)
ERROR Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check the render method of `App`.
This error is located at:
in App (created by ExpoRoot)
in ExpoRoot
in RCTView (created by View)
in View (created by AppContainer)
in DevAppContainer (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in main(RootComponent)

Related

error invalid hook call issue while using Redux store to do api calls in React-Native

So as preface I am learning react-native and I am developing an app which connects to an backend api using redux.
I am getting the following error when I try to run the app.
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
This error is located at:
in ComplaintsMenu (created by HomePage)
in RCTView (created by View)
in View (created by HomePage)
in RCTView (created by View)
in View (created by HomePage)
in HomePage (created by SceneView)
in StaticContainer
in EnsureSingleNavigator (created by SceneView)
in SceneView (created by CardContainer)
in RCTView (created by View)
in View (created by CardContainer)
in RCTView (created by View)
in View (created by CardContainer)
in RCTView (created by View)
in View
in CardSheet (created by Card)
in RCTView (created by View)
in View (created by AnimatedComponent)
in AnimatedComponent
in AnimatedComponentWrapper (created by PanGestureHandler)
in PanGestureHandler (created by PanGestureHandler)
in PanGestureHandler (created by Card)
in RCTView (created by View)
in View (created by AnimatedComponent)
in AnimatedComponent
in AnimatedComponentWrapper (created by Card)
in RCTView (created by View)
in View (created by Card)
in Card (created by CardContainer)
in CardContainer (created by CardStack)
in RNSScreen (created by AnimatedComponent)
in AnimatedComponent
in AnimatedComponentWrapper (created by InnerScreen)
in Suspender (created by Freeze)
in Suspense (created by Freeze)
in Freeze (created by DelayedFreeze)
in DelayedFreeze (created by InnerScreen)
in InnerScreen (created by Screen)
in Screen (created by MaybeScreen)
in MaybeScreen (created by CardStack)
in RNSScreenContainer (created by ScreenContainer)
in ScreenContainer (created by MaybeScreenContainer)
in MaybeScreenContainer (created by CardStack)
in RCTView (created by View)
in View (created by Background)
in Background (created by CardStack)
in CardStack (created by HeaderShownContext)
in RNCSafeAreaProvider (created by SafeAreaProvider)
in SafeAreaProvider (created by SafeAreaInsetsContext)
in SafeAreaProviderCompat (created by StackView)
in RNGestureHandlerRootView (created by GestureHandlerRootView)
in GestureHandlerRootView (created by StackView)
in StackView (created by StackNavigator)
in PreventRemoveProvider (created by NavigationContent)
in NavigationContent
in Unknown (created by StackNavigator)
in StackNavigator (created by App)
in EnsureSingleNavigator
in BaseNavigationContainer
in ThemeProvider
in NavigationContainerInner (created by App)
in RCTView (created by View)
in View (created by SafeAreaWrap)
in SafeAreaWrap (created by App)
in Provider (created by App)
in App (created by withDevTools(App))
in withDevTools(App)
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in main(RootComponent)
my reducer is-
export function complaintReducer(state = initalComplaintsFormState, action) {
switch (action.type) {
//...other cases
case GET_COMPLAINT_LIST:
return { ...state, complaintList: action.payload };
default:
return state;
}
}
and my ComplaintsMenu component has the following code-
//...other imports
import { useSelector, useDispatch } from "react-redux";
import { getComplaintList } from "../Redux/Actions";
export default function ComplaintsMenu() {
const { ComplaintList } = useSelector((state) => state.complaintReducer);
const dispatch = useDispatch;
----------
// From my understanding this is where the issue is, since the dispatch function (hook?) is being called conditionally under the useEffect hook. but I don't understand what exactly is happening and how to implement what I am trying to implement, I followed steps from the youtube video mentioned below where he did the same thing
useEffect(() =\> {
dispatch(getComplaintList());
}, \[\]);
return (
\<FlatList
data={ComplaintList}
renderItem={({ item }) =\> (
\<ComplaintCard
key={item.complaint_id}
title={item.issue}
status={item.status}
/\>
)}
/\>
);
these are my dependencies version
{
"name": "poll-app",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web"
},
"dependencies": {
"#expo-google-fonts/inter": "^0.2.2",
"#expo/webpack-config": "^0.17.2",
"#react-navigation/native": "^6.1.3",
"#react-navigation/stack": "^6.3.12",
"expo": "\~47.0.12",
"expo-status-bar": "\~1.4.2",
"react": "18.1.0",
"react-dom": "18.1.0",
"react-native": "0.70.5",
"react-native-safe-area-context": "4.4.1",
"react-native-screens": "\~3.18.0",
"react-native-web": "\~0.18.9",
"react-redux": "^8.0.5",
"redux": "^4.2.1",
"redux-thunk": "^2.4.2"
},
"devDependencies": {
"#babel/core": "^7.12.9",
"eslint-plugin-react-hooks": "^4.6.0"
},
"private": true
}
Note: I am using an older version of node because expo had some legacy dependency issue with the current lts version of node
I have tried This answer, I believe my question is a duplicate of this question, I don't know how to revive unanswered questions so I am asking this question here, I apologize if this is not the correct way to ask for the answer on stack.
I followed this Youtube tutorial for the implementation
As of now
I have reinstalled react-redux and redux and also tried npm update.
To check for the react version mismatch issue. I have also verified that all the dependencies use the same react version.
I have included my thoughts about the problem in the a comment in the code above
try like this const dispatch = useDispatch(), you're not calling the function useDispatch

TypeError: Cannot read property 'isFileUploadSupported' of null

I am trying to render a HTML snippet in my React-Native app using react-native-webview
, I also tried react-native-render-html, but in this CSS is not work that much.
This is my Error Stack
ERROR TypeError: Cannot read property 'isFileUploadSupported' of null, js engine: hermes
at App (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.dbc&modulesOnly=false&runModule=true:93600:36)
at RCTView
at View
at RCTView
at View
at AppContainer (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.dbc&modulesOnly=false&runModule=true:85300:36)
at DBC(RootComponent) (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.dbc&modulesOnly=false&runModule=true:89907:28)
ERROR Error: Requiring module "node_modules/react-native-webview/index.js", which threw an exception: TypeError: Cannot read property 'isFileUploadSupported' of null, js engine: hermes
at App (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.dbc&modulesOnly=false&runModule=true:93600:36)
at RCTView
at View
at RCTView
at View
at AppContainer (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.dbc&modulesOnly=false&runModule=true:85300:36)
at DBC(RootComponent) (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.dbc&modulesOnly=false&runModule=true:89907:28)
ERROR TypeError: Cannot read property 'WebView' of undefined
This error is located at:
in App
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in DBC(RootComponent), js engine: hermes
And This is my code
import {SafeAreaView, ScrollView, useWindowDimensions} from 'react-native';
import {WebView} from 'react-native-webview';
import {getTemplate} from './template';
export default class App extends Component {
render() {
const template = getTemplate();
const source = {
html: template,
};
return (
<SafeAreaView>
<ScrollView>
<ScrollView horizontal={true}>
<WebView
ref={r => (this.webref = r)}
originWhitelist={['*']}
source={source}
/>
</ScrollView>
</ScrollView>
</SafeAreaView>
);
}
}

Render Error requireNativeComponent: "RNGestureHandlerRootView" was not found in the UIManager

Help me to fix this error.
Render Error
requireNativeComponent: "RNGestureHandlerRootView" was not found in the UIManager.
Invariant Violation: requireNativeComponent: "RNGestureHandlerRootView" was not found in the UIManager.
This error is located at:in RNGestureHandlerRootView (created by GestureHandlerRootView)in GestureHandlerRootView (created by DrawerView)in RCTView (created by View)in View in SafeAreaProviderCompat (created by DrawerView)in DrawerView (created by DrawerNavigator)in Unknown (created by DrawerNavigator)in DrawerNavigator (created by DrawerNavigator)in DrawerNavigator (created by SceneView)in StaticContainerin EnsureSingleNavigator (created by SceneView)in SceneView (created by SceneView)in RCTView (created by View)in View (created by DebugContainer)in DebugContainer (created by MaybeNestedStack)in MaybeNestedStack (created by SceneView)in RNSScreen (created by AnimatedComponent)in AnimatedComponent in AnimatedComponentWrapper (created by Screen)in MaybeFreeze (created by Screen)in Screen (created by SceneView)in SceneView (created by NativeStackViewInner)in RNSScreenStack (created by ScreenStack)in ScreenStack (created by NativeStackViewInner)in NativeStackViewInner (created by NativeStackView)in RNCSafeAreaProvider (created by SafeAreaProvider)in SafeAreaProvider in SafeAreaProviderCompat (created by NativeStackView)in NativeStackView (created by NativeStackNavigator)in Unknown (created by NativeStackNavigator)in NativeStackNavigator (created by AuthStack)in AuthStack (created by App)in EnsureSingleNavigator in BaseNavigationContainer in ThemeProviderin NavigationContainerInner (created by App)in App (created by ExpoRoot) in ExpoRoot in RCTView (created by View)in View (created by AppContainer) in RCTView (created by View)in View (created by AppContainer)in AppContainer
This error occurs when I try to add a Drawer Navigator to the android application that I am implementing using React-Native.
I run npm install --save react-native-gesture-handler and add import "react-native-gesture-handler"; on top of my root file. But the same error occurs.
Versions:
"react-native": "0.64.3",
"react-native-gesture-handler": "^2.3.2",
"react-navigation-drawer": "^2.7.2",
"react-native-reanimated": "^2.4.1",
Maybe you forgot to wrap your app in this:
export default function App() {
return (
<GestureHandlerRootView>
{/* content */}
</GestureHandlerRootView>;
)
}
Friendly reminder to always read installation docs. I feel like you didn't do that but I am sorry if I am wrong.
Here is the link to the react-native-gesture-handler installation doc:
https://docs.swmansion.com/react-native-gesture-handler/docs/installation
In case you installed and follow all steps about drawer navigation and keep coming out the same, so you have to rebuild the app with npx react-native run-android -- --reset-cache just in case uninstall the app.

The app is crashing when I navigate while going back using pop()

Initially, the app was working fine, after which I created a custom stack over Authenticated stack (screens when the user is Authenticated).
The app is crashing when I navigate while going back using pop(), but it works fine with navigate or goBack().
inActiveUser => Check for user touch events using Pan Responder, to log out when he is inactive.
AuthenticatedNavigator => Routes where the authenticated user is allowed.
New stack:
New Authenticated stack is implemented over Authentcated stack.
Panresponder
"react-dom": "^16.12.0",
"react-native": "0.61.5",
"react-native-gesture-handler": "^1.5.3",
"react-navigation": "^4.0.10",
"react-navigation-drawer": "^2.3.3",
"react-navigation-stack": "^2.0.10",
import React from 'react';
import UserActivity from 'utils/inactiveUser';
import AuthenticatedNavigator from '../AuthenticatedStack';
class CustomStack extends React.Component {
panHandlers = {};
userActivity;
constructor(props) {
super(props);
this.userActivity = new UserActivity();
}
componentDidMount() {
this.userActivity.startTimer();
this.panHandlers = this.userActivity.panHandlers();
}
static router = AuthenticatedNavigator.router;
render() {
const { navigation } = this.props;
return <AuthenticatedNavigator screenProps={{ ...this.panHandlers }} navigation={navigation} />;
}
}
export default CustomStack;
/*******************************************/
TypeError: Cannot read property 'state' of undefined
This error is located at:
in Navigator (at SceneView.js:9)
in SceneView (at StackView.tsx:269)
in RCTView (at CardContainer.tsx:171)
in RCTView (at CardContainer.tsx:170)
in RCTView (at Card.tsx:486)
in RCTView (at createAnimatedComponent.js:151)
in AnimatedComponent (at Card.tsx:473)
in PanGestureHandler (at Card.tsx:466)
in RCTView (at createAnimatedComponent.js:151)
in AnimatedComponent (at Card.tsx:462)
in RCTView (at Card.tsx:455)
in Card (at CardContainer.tsx:138)
in CardContainer (at CardStack.tsx:501)
in RCTView (at CardStack.tsx:110)
in MaybeScreen (at CardStack.tsx:494)
in RCTView (at CardStack.tsx:93)
in MaybeScreenContainer (at CardStack.tsx:401)
in CardStack (at StackView.tsx:377)
in KeyboardManager (at StackView.tsx:375)
in RNCSafeAreaView (at src/index.tsx:26)
in SafeAreaProvider (at SafeAreaProviderCompat.tsx:34)
in SafeAreaProviderCompat (at StackView.tsx:372)
in StackView (at StackView.tsx:41)
in StackView (at createStackNavigator.tsx:33)
in Unknown (at createNavigator.js:80)
in Navigator (at SceneView.js:9)
in SceneView (at DrawerView.tsx:183)
in RCTView (at ResourceSavingScene.tsx:37)
in RCTView (at ResourceSavingScene.tsx:26)
in ResourceSavingScene (at DrawerView.tsx:175)
in RCTView (at screens.native.js:132)
in ScreenContainer (at DrawerView.tsx:164)
in RCTView (at createAnimatedComponent.js:233)
in AnimatedComponent(Component) (at Drawer.tsx:539)
in RCTView (at createAnimatedComponent.js:233)
in AnimatedComponent(Component) (at Drawer.tsx:535)
in PanGestureHandler (at Drawer.tsx:525)
in DrawerView (at DrawerView.tsx:251)
in DrawerView (at createNavigator.js:80)
in Navigator (at CustomStack/index.js:24)
in CustomStack (at SceneView.js:9)
in SceneView (at SwitchView.js:12)
in SwitchView (at createNavigator.js:80)
in Navigator (at createAppContainer.js:430)
in NavigationContainer (at src/index.js:52)
in RNCAppearanceProvider (at src/index.tsx:70)
in AppearanceProvider (at src/index.js:51)
in App (at renderApplication.js:40)
in RCTView (at AppContainer.js:101)
in ChildrenWrapper (at wrapRootComponent.js:9)
in _default (at wrapRootComponent.js:8)
in Root (at AppContainer.js:115)
in RCTView (at AppContainer.js:119)
in AppContainer (at renderApplication.js:39)
TypeError: Cannot read property 'state' of undefined
This error is located at:
in NavigationContainer (at src/index.js:52)
in RNCAppearanceProvider (at src/index.tsx:70)
in AppearanceProvider (at src/index.js:51)
in App (at renderApplication.js:40)
in RCTView (at AppContainer.js:101)
in ChildrenWrapper (at wrapRootComponent.js:9)
in _default (at wrapRootComponent.js:8)
in Root (at AppContainer.js:115)
in RCTView (at AppContainer.js:119)
in AppContainer (at renderApplication.js:39)
BugReporting extraData:
{AppRegistry.runApplication1: "Running "smemobileapp" with {"rootTag":21,"initialProps":{}}"}
AppRegistry.runApplication1: (...)
get AppRegistry.runApplication1: ƒ ()
set AppRegistry.runApplication1: ƒ ()
__proto__: Object
Link referred
https://medium.com/#benjaminwfox/share-state-between-screens-with-custom-navigators-in-react-navigation-62a34e3c7f97
https://reactnavigation.org/docs/en/custom-routers.html
React with ES7: Uncaught TypeError: Cannot read property 'state' of undefined
Unable to access React instance (this) inside event handler
React-Native App getting crashed on navigate
I was passing the wrong object. {{...this.panHandlers}} instead of { ...this.panHandlers}
class CustomStack extends React.Component {
panHandlers = {};
userActivity;
constructor(props) {
super(props);
this.userActivity = new UserActivity();
}
componentDidMount() {
this.userActivity.startTimer();
this.panHandlers = this.userActivity.panHandlers();
}
static router = AuthenticatedNavigator.router;
render() {
const {
navigation
} = this.props;
return <AuthenticatedNavigator screenProps = { ...this.panHandlers
}
navigation = {
navigation
}
/>;
}
}

Why do I need to export the component to pass it to the registerComponent method?

This code works fine:
import React, { Component } from 'react';
import { Text, AppRegistry } from 'react-native';
export default class App extends Component {
render() {
return (
<Text>Hello World!</Text>
);
}
}
AppRegistry.registerComponent('SampleApp', () => App);
But I get the error when I do not export the App component:
import React, { Component } from 'react';
import { Text, AppRegistry } from 'react-native';
class App extends Component {
render() {
return (
<Text>Hello World!</Text>
);
}
}
AppRegistry.registerComponent('SampleApp', () => App);
Why do I need to export the App component to pass it to the registerComponent method? Is this because AppRegistry.registerComponent is not inside the App class component? Do I need to export class components even if there were in the same file?
Here is the error I get in the iOS simulator:
*I use expo.
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check the render method of `ExpoRootComponent`.
This error is located at:
in RootErrorBoundary (at registerRootComponent.js:34)
in ExpoRootComponent (at renderApplication.js:33)
in RCTView (at View.js:60)
in View (at AppContainer.js:102)
in RCTView (at View.js:60)
in View (at AppContainer.js:122)
in AppContainer (at renderApplication.js:32)
throwOnInvalidElementType
ReactNativeRenderer-dev.js:4705:2
createFiberFromElement
ReactNativeRenderer-dev.js:4663:16
reconcileSingleElement
ReactNativeRenderer-dev.js:8337:22
reconcileChildFibers
ReactNativeRenderer-dev.js:8421:12
reconcileChildrenAtExpirationTime
ReactNativeRenderer-dev.js:8621:29
finishClassComponent
ReactNativeRenderer-dev.js:8839:4
updateClassComponent
ReactNativeRenderer-dev.js:8761:11
beginWork
ReactNativeRenderer-dev.js:9580:15
performUnitOfWork
ReactNativeRenderer-dev.js:12924:15
Something needs to be exported in order for it to be imported later on by some other script.
According to MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
The export statement is used when creating JavaScript modules to export functions, objects, or primitive values from the module so they can be used by other programs with the import statement.
My guess is the registerComponent method expects a module as one of the parameters.