Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6214

Typescript error JSX element type 'View' is not a constructor function for JSX elements

$
0
0

The program itself runs fine, but Typescript is underlining a lot of items in red in my return function for my components. Specifically anything coming out of my react-native import.

Anything like View, Button, and the like are throwing these "errors". I say errors in quotes because the app runs without any problems at all. Typescript within my IDE (VS Code) is the only thing complaining. It throws these errors if I choose (through the bottom right status bar selector) JavaScript React or TypeScript React. Here is an example:

Text Problem

Here is the important bits of my package.json

"scripts": {"start": "expo start","android": "expo start --android","ios": "expo start --ios","web": "expo start --web","eject": "expo eject"  },"dependencies": {"@react-navigation/native": "^5.7.6","@react-navigation/stack": "^5.9.3","expo": "~39.0.2","expo-status-bar": "~1.0.2","react": "16.13.1","react-dom": "16.13.1","react-native": "https://github.com/expo/react-native/archive/sdk-39.0.3.tar.gz","react-native-screens": "~2.10.1","react-native-web": "~0.13.12","react-native-gesture-handler": "~1.7.0","react-native-reanimated": "~1.13.0","react-native-safe-area-context": "3.1.4","@react-native-community/masked-view": "0.1.10"  },"devDependencies": {"react-native-web": "~0.13.7","@types/react": "*","@types/react-dom": "*","@types/react-native": "*","typescript": "~3.9.5"  },

And here is what a file looks like that is throwing these errors:

import { StatusBar } from "expo-status-bar";import React, { useState } from "react";import { StyleSheet, Text, View, TextInput, Button } from "react-native";const SummaryScreen = ({ navigation }) => {    const accountDetailsPage = () => {        navigation.navigate("Account Details");    };    const contactDetailsPage = () => {        navigation.navigate("Contact Details");    };    return (<View style={styles.container}><Text>HERE IS A BUNCH OF TEXT</Text><Button title="Account Details" onPress={accountDetailsPage} /><Button title="Contact Details" onPress={contactDetailsPage} /></View>    );};const styles = StyleSheet.create({    container: {        flex: 1,        backgroundColor: "#fff",        flexDirection: "column",        alignItems: "center",        justifyContent: "center",    },});export default SummaryScreen;

I think it's important to note I do NOT get these errors on components created from @react-navigation such as <Navigator> and <Stack.Screen ...

Here is my tsconfig as well:

{"compilerOptions": {"allowSyntheticDefaultImports": true,"jsx": "react-native","lib": ["dom", "esnext"],"moduleResolution": "node","noEmit": true,"skipLibCheck": true,"resolveJsonModule": true,"strict": true    }}

Somewhat related, something in VS Code is complaining it can't find the module for useState but that also works fine when running, with no errors


Viewing all articles
Browse latest Browse all 6214

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>