I’m using pretty old Material UI (Ver. 0.20.1) components.
Here’s a chunk of my code:
JavaScript
x
11
11
1
return(
2
<>
3
<Card>
4
<CardHeader
5
actAsExpander={true}
6
showExpandableButton={true}
7
title = {user.name}
8
subtitle={`${user.email}, ${user.phone}, ${user.isproved ? "Yes" : "No"}, Friends: ${user.friends? user.friends : "None"}`}
9
/>
10
</Card>)
11
So i have a subtitle string with a bunch of variables in it that i wanted to use a line break to separate visually but adding n
or even '...string' + <br/> + 'string...'
doesn’t work. What should i do?
Advertisement
Answer
I can’t test in a sandBox but if we look in the version 0.20.1 documentation of Material-ui we can read that:
property: subtitle type: node Can be used to render a subtitle in Card Header.
so you can create a node for example a list:
JavaScript
1
2
1
const subtitle =<ul><li>{user.email},</li><li>{user.phone},</li><li> {user.isproved ? "Yes" : "No"},</li><li> Friends: {user.friends? user.friends : "None"}</li></ul>;
2
and pass it to subtitle
like this:
JavaScript
1
13
13
1
return(
2
<>
3
<Card>
4
<CardHeader
5
actAsExpander={true}
6
showExpandableButton={true}
7
title = {user.name}
8
subtitle={subtitle}
9
/>
10
</Card>
11
</>
12
)
13
UPDATE:
I found a codeSanbox template so here a working example