【问题标题】:Material Ui - Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/functionMaterial Ui - 未捕获错误:不变违规:元素类型无效:预期字符串(用于内置组件)或类/函数
【发布时间】:2020-09-07 05:02:29
【问题描述】:

当我加载这个 LoginScreen.js 时,我得到了上面提到的异常。 在此之前我已经安装了

npm install @material-ui/core

import React from 'react';
import {Button} from '@material-ui/core/Button';
import { View } from 'react-native';

export default function LoginScreen() {

  return (
    <View>
      <Button></Button>
    </View>

  );
}

【问题讨论】:

    标签: android reactjs react-native android-studio


    【解决方案1】:

    您需要以不同的方式导入。尝试如下:

    import Button from '@material-ui/core/Button';
    
    // or
    import { Button } from '@material-ui/core';
    

    在此处查看官方文档:Button API - Import

    我希望这会有所帮助!

    【讨论】:

    • 这次我得到了一个新的异常,即 Invariant Violation:View config not found for a name span。
    • @SyedSabiyullah 对于那个错误,this question 有帮助吗?
    猜你喜欢
    • 2020-02-29
    • 1970-01-01
    • 2020-10-05
    • 2016-07-29
    • 2016-02-06
    • 2020-06-27
    • 1970-01-01
    • 1970-01-01
    • 2019-12-31
    相关资源
    最近更新 更多