【发布时间】:2020-12-17 14:01:29
【问题描述】:
App.js
import React, { Component } from 'react'
import { StyleSheet, View } from 'react-native'
import { Colors } from 'react-native/Libraries/NewAppScreen'
import { NewsCardMaterial } from "./components/NewsCardMaterial"
function App() {
return (
<>
<View>
<NewsCardMaterial />
</View>
</>
)
}
const Styles = StyleSheet.create({
scrollView: {
backgroundColor: Colors.lighter,
},
engine: {
position: 'absolute',
right: 0,
},
body: {
backgroundColor: Colors.white,
},
sectionContainer: {
marginTop: 32,
paddingHorizontal: 24,
},
sectionTitle: {
fontSize: 24,
fontWeight: '600',
color: Colors.black,
},
sectionDescription: {
marginTop: 8,
fontSize: 18,
fontWeight: '400',
color: Colors.dark,
},
highlight: {
fontWeight: '700',
},
footer: {
color: Colors.dark,
fontSize: 12,
fontWeight: '600',
padding: 4,
paddingRight: 12,
textAlign: 'right',
},
})
export default App
NewsCardMaterial.js
import React, { Component } from "react"
import { makeStyles } from "@material-ui/core/styles"
import Card from "@material-ui/core/Card"
import CardHeader from "@material-ui/core/CardHeader"
import CardMedia from "@material-ui/core/CardMedia"
import CardContent from "@material-ui/core/CardContent"
import { red } from "@material-ui/core/colors"
const UseStyles = makeStyles((theme) => ({
root: {
maxWidth: 345
},
media: {
height: 0,
paddingTop: "56.25%" // 16:9
},
expand: {
transform: "rotate(0deg)",
marginLeft: "auto",
transition: theme.transitions.create("transform", {
duration: theme.transitions.duration.shortest
})
},
expandOpen: {
transform: "rotate(180deg)"
},
avatar: {
backgroundColor: red[500]
}
}))
const MyText = " This impressive paella is a perfect party dish and a fun meal to cook" +
"together with your guests. Add 1 cup of frozen peas along with the" +
"mussels, if you like."
export default function NewsCardMaterial() {
const Classes = UseStyles()
return (
<div>
<Card className={Classes.root}>
<CardHeader
title="Shrimp and Chorizo Paella"
subheader="September 14, 2016 | Orissa, India"
/>
<CardMedia
className={Classes.media}
image={
"https://image.freepik.com/free-photo/river-foggy-mountains-landscape_1204-511.jpg"
}
title="Paella dish"
/>
<CardContent text={MyText} />
</Card>
</div>
)
}
index.js
/**
* @format
*/
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
AppRegistry.registerComponent(appName, () => App);
我看到以下错误 -
到目前为止我做了什么 -
- 在调用时重新检查导出组件的名称
- 在导入时将 NewsCardMaterial 更改为 {NewsCardMaterial}
- 安装了最新版本的 react、react-native 和 @material-ui/core
- 包括在内和不包括在内
- 删除了不必要的 cmets、空格并格式化了文档
我在这里创建了一个 sandbox,其中包含与卡相同的代码,但是,这里无法重现此错误 -
【问题讨论】:
标签: react-native material-ui components