Cree el archivo src/components/Indicator.tsx
con el componente Fragment:
export default function Indicator() {
return (
<>
Indicator
</>
)
}
En App.tsx
importe el componente Indicator y use en el contenido a renderizar:
import Indicator from './components/Indicator';
function App() {
return (
...
<Grid xs={6} md={4} lg={2}>
<Indicator />
</Grid>
...
)
}
export default App
(STOP 1) Compruebe el resultado en el navegador.
Agregue la interfaz Config
al componente Indicator
...
interface Config {
title?: String;
subtitle?: String;
value: Number;
}
export default function Indicator(config: Config) {
return (
<>
{config.title}<br/>
{config.value.toString()}<br/>
{config.subtitle}
</>
)
}
En App.tsx
, agregue las propiedades y los valores del componente Indicator
import Indicator from './components/Indicator';
function App() {
return (
...
<Grid xs={6} md={4} lg={2}>
<Indicator title='Precipitación' subtitle='Probabilidad' value={0.13} />
</Grid>
...
)
}
export default App
(STOP 2) Compruebe el resultado en el navegador.
En Indicator.tsx
, agregue la referencia a los componentes Typography y Paper
import Typography from '@mui/material/Typography';
import Paper from '@mui/material/Paper';
Use los componentes Typography y Paper
...
export default function Indicator(config: Config) {
return (
<Paper
sx={{
p: 2,
display: 'flex',
flexDirection: 'column'
}}
>
<Typography component="h2" variant="h6" color="primary" gutterBottom>
{config.title}
</Typography>
<Typography component="p" variant="h4">
{config.value.toString()}
</Typography>
<Typography color="text.secondary" sx={{ flex: 1 }}>
{config.subtitle}
</Typography>
</Paper>
)
}
(STOP 3) Compruebe el resultado en el navegador.
assets
dentro del proyecto.Cree el componente src/components/Summary.tsx
, importe y use los componentes Card y los componentes relacionados:
import Typography from '@mui/material/Typography';
import Card from '@mui/material/Card';
import CardContent from '@mui/material/CardContent';
import CardMedia from '@mui/material/CardMedia';
import { CardActionArea } from '@mui/material';
import sunrise from '../assets/sunrise.jpeg'
export default function Summary() {
return (
<Card sx={{ maxWidth: 345 }}>
<CardActionArea>
<CardMedia
component="img"
height="140"
image={sunrise}
alt="Amanecer"
/>
<CardContent>
<Typography gutterBottom component="h2" variant="h6" color="primary">
Amanecer
</Typography>
<Typography component="p" variant="h4">
05:19:08
</Typography>
<Typography color="text.secondary" sx={{ flex: 1 }}>
en 17 Junio, 2024
</Typography>
</CardContent>
</CardActionArea>
</Card>
)
}
En App.tsx
, importe el componente Summary y use en el contenido a renderizar:
import Summary from './components/Summary';
function App() {
return (
...
<Grid xs={6} sm={4} md={3} lg={2}>
<Summary></Summary>
</Grid>
...
)
}
export default App
src/components/BasicTable.tsx
App.tsx
, importe el componente BasicTable y use en el contenido a renderizar: import BasicTable from './components/BasicTable';
function App() {
return (
...
<Grid xs={12} md={6} lg={9} >
<BasicTable />
</Grid>
...
)
}
export default App
⚛️ Do you know how to name React components with the Base + Composite + Suffix Pattern?
— George Moller (@_georgemoller) November 6, 2023
You can use this pattern to create clear and consistent component names in your projects. pic.twitter.com/xxopzpmvwJ
component, interface, props