I have a problem with the structure of my project and i wanted to know what is the best way to solve my problem. I have three components and two level of nesting:
my grand parent component:
function WhatClientSay() {
return (
<Container
component="section"
>
<ClientCard />
</Container>
);
}
the ClientCard component:
import ClientAvatar from "../ClientAvatar/ClientAvatar";
function ClientCard(props) {
return (
<div>
<Box>
<Typography
fontWeight="600"
>
what client say
</Typography>
<Typography>
“Excepteur sin occaecat cupidatat proident. It’s sunt in culpa qui
officia deserunt mollit anim id
</Typography>
<Box sx={{ display: "grid", placeItems: "center" }}>
<ClientAvatar
username="naomi hamilton"
role="customer"
rate={5}
profileImg={profileImg}
/>
</Box>
</Box>
</div>
);
}
and my ClientAvatar component (it just renders some props beside a photo as an avatar) :
function ClientAvatar({ profileImg, username, role, rate }: AvatarProps) {
return (
<>
<Box sx={{ mt: 3, "& img": { width: 70, height: 70 } }}>
<Grid container spacing={1}>
<Grid item>
<img src={profileImg} alt="profile" />
</Grid>
<Grid item>
<Grid
container
direction="column"
spacing={0}
justifyContent="space-between"
alignItems="flex-start"
>
<Grid item>
<Typography
sx={{
fontSize: 15,
textTransform: "uppercase",
fontWeight: "600",
}}
>
{username}
</Typography>
</Grid>
<Grid item>
<Typography
sx={{
fontSize: 13,
textTransform: "uppercase",
fontWeight: "600",
mb: 1,
}}
>
{role}
</Typography>
</Grid>
<Grid item>
<Rating size="small" name="read-only" value={rate} readOnly />
</Grid>
</Grid>
</Grid>
</Grid>
</Box>
</>
);
so my questions are:
what is the best way to pass data to my components? should i pass the ClientAvatar props from the grandparent component to the child and then to its child??
what is the best way of writing hard coded values like titles and subtitles?? should i store them in an object and pass them as props to the child component? or should i make an object like this and pass it to the Typography?
const contexts = {title : 'what client say' , subtitle:' lorem lorem' }
thanks in advance.