【问题标题】:React Native / Expo / Typescript: JSX element type 'Text' does not have any construct or call signatures.ts (2604)React Native / Expo / Typescript:JSX 元素类型 \'Text\' 没有任何构造或调用 signatures.ts (2604)
【发布时间】:2022-11-13 16:12:00
【问题描述】:

任何人都可以帮助我使用 React Native 和 Expo 的早期旅程吗?

JSX 元素类型“文本”没有任何构造或调用 signatures.ts(2604)

应用程序.tsx

import { StyleSheet, Text, View } from 'react-native';
import FrontCard from './components/FrontCard';

const App = () => {
  return (
    <View style={styles.container}>
      <FrontCard />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

export default App;

FrontCard.tsx

import React from 'react'
import Text, { View } from 'react-native'

const FrontCard: React.FC = () => {
  return (
    <View>
      <Text>test</Text>
    </View>
  )
}

export default FrontCard;

包.json

{
  "dependencies": {
    "expo": "^46.0.0",
    "react": "18.0.0",
    "react-dom": "18.0.0",
    "react-native": "0.69.4",
    "react-native-web": "~0.18.7"
  },
  "devDependencies": {
    "@babel/core": "^7.18.6",
    "@types/react": "~18.0.0",
    "@types/react-native": "~0.69.1",
    "typescript": "^4.6.3"
  },
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web"
  },
  "version": "1.0.0",
  "private": true,
  "name": "canumind"
}

我尝试了以下搜索结果中提到的一些不同的东西: https://www.google.com/search?q=JSX+element+type+does+not+have+any+construct+or+call+signatures.ts+(2604)&rlz=1C1PRFI_enGB834GB834&sxsrf=ALiCzsbu2XjELqIQ0dOLQwdnq3sAj_g7PA:1668253602337&source=lnt&tbs=qdr:y&sa=X&ved=2ahUKEwiF8fL6yKj7AhUJZMAKHRf0CqIQpwV6BAgBEBo&biw=1120&bih=972&dpr=1

【问题讨论】:

    标签: reactjs typescript react-native npm expo


    【解决方案1】:

    Text 不是默认出口,这是一个命名为出口。

    import Text, { View } from 'react-native'; // wrong
    
    import { Text, View } from 'react-native'; // correct
    

    更多信息:https://reactnative.dev/docs/text

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-04
      • 2020-06-08
      • 2019-04-26
      • 2023-01-30
      • 2021-07-10
      • 2021-11-30
      • 2016-10-07
      • 2016-03-05
      相关资源
      最近更新 更多