Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is difference between variant vs component in typography for library React Material UI

I am using React Material UI component. Typography component has 2 props, variant and component.What is the difference between these props.

like image 230
user1388835 Avatar asked Jan 19 '21 06:01

user1388835


People also ask

What is the difference between variant and component in material UI?

variant => you use styles of normal html tag. component => you use a React element for root node. about "you use styles of normal html tag": well, img for example is a "normal html tag", what do you mean by "using" its styles?

What is variant in typography?

variant: It is used to set the theme typography styles. Example: h1, h2, h3, h4, h5, h6, subtitle1, subtitle2, body1, body2, caption, button, overline, srOnly or inherit. classes: It is the custom CSS object to override the styles. paragraph: If this is true the text will have a bottom margin. Example: true or false.

What is variant in Reactjs?

Use the variant API to apply complex styles to a component based on a single prop. This can be a handy way to support slight stylistic variations in button or typography components. Import the variant function and pass variant style objects in your component definition.

How does material UI align typography?

import Typography from '@material-ui/core/Typography'; // OR import { Typography } from '@material-ui/core'; Syntax: It sets the alignment property. Property Values: left: It aligns text along the left side of a page or containing element.


2 Answers

Some predefine styles can be used with variant but final HTML element to be rendered can be set with component. e.g. you can use variant="body1" with component="h2" or variant="body2" with component="h2" that has smaller font-size.

like image 139
BeHappy Avatar answered Oct 20 '22 05:10

BeHappy


variant => you use styles of normal html tag.

component => you use a React element for root node.

like image 30
Thanh Avatar answered Oct 20 '22 05:10

Thanh