首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TS2786 TypeScript不重新组合UI-Kitten组件

TS2786 TypeScript不重新组合UI-Kitten组件
EN

Stack Overflow用户
提问于 2022-04-25 15:52:04
回答 1查看 1.1K关注 0票数 4

IDE上的错误消息:

TS2786:“ApplicationProvider”不能用作JSX组件。 它的实例类型'ApplicationProvider‘不是一个有效的JSX元素。 由'render()‘返回的类型在这些类型之间不兼容。 类型'React.ReactNode‘不能指定为键入React.ReactNode 类型“{}”不能指定为键入“ReactNode”。 键入“{}”不能指定键入“ReactPortal”。

不仅仅是ApplicationProvider,而且我从UI-kitten/components中导入的每个组件都存在“不是一个有效的JSX元素”错误。

代码语言:javascript
复制
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * Generated with the UI Kitten TypeScript template
 * https://github.com/akveo/react-native-ui-kitten
 *
 * Documentation: https://akveo.github.io/react-native-ui-kitten/docs
 *
 * @format
 */

import React from 'react';
import {
  ImageProps,
  StyleSheet,
} from 'react-native';
import {
  ApplicationProvider,
  Button,
  Icon,
  IconRegistry,
  Layout,
  Text,
} from '@ui-kitten/components';
import { EvaIconsPack } from '@ui-kitten/eva-icons';
import * as eva from '@eva-design/eva';

/**
 * Use any valid `name` property from eva icons (e.g `github`, or `heart-outline`)
 * https://akveo.github.io/eva-icons
 */
const HeartIcon = (props?: Partial<ImageProps>): React.ReactElement<ImageProps> => (
  <Icon {...props} name='heart'/>
);

export default (): React.ReactFragment => (
  <>
    <IconRegistry icons={EvaIconsPack}/>
    <ApplicationProvider {...eva} theme={eva.light}>
      <Layout style={styles.container}>
        <Text style={styles.text} category='h1'>
          Welcome to UI Kitten 
        </Text>
        <Text style={styles.text} category='s1'>
          Start with editing App.js to configure your App
        </Text>
        <Text style={styles.text} appearance='hint'>
          For example, try changing theme to Dark by using eva.dark
        </Text>
        <Button style={styles.likeButton} accessoryLeft={HeartIcon}>
          LIKE
        </Button>
      </Layout>
    </ApplicationProvider>
  </>
);

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  text: {
    textAlign: 'center',
  },
  likeButton: {
    marginVertical: 16,
  },
});

复制:

代码语言:javascript
复制
npx react-native init MyApp --template @ui-kitten/template-ts

在更新@type/react最新版本(18.0.6)时,似乎可以解决这个问题。但世博并不支持18版,这似乎也是最近才提出来的一个问题。

EN

回答 1

Stack Overflow用户

发布于 2022-05-22 20:44:56

这里.

  1. "resolutions": { "@types/react": "~17.0.21" },添加到package.json
  2. 删除node_modules
  3. yarn install或同等方式重新安装
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72002300

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档