An Interest In:
Web News this Week
- April 27, 2024
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
April 9, 2022 10:37 am GMT
Original Link: https://dev.to/himanshupal0001/ways-to-pass-multiple-classes-in-react-p46
Ways to pass multiple classes in react!!!
By passing props
import React from 'react';import { makeStyles } from '@material-ui/core';const useStyles = makeStyles({ firstStyle: { backgroundColor: props => props.backgroundColor, }, secondStyle: { color: props => props.color, },});const MyComponent = ({children, ...props}) =>{ const { firstStyle, secondStyle } = useStyles(props); return( <div className={`${firstStyle} ${secondStyle}`}> {children} </div> )}export default MyComponent;Now you can use it like:<MyComponent color="yellow" backgroundColor="purple"> Well done</MyComponent>
By clsx
First install it:npm install --save clsxThen import it in your component file:import clsx from 'clsx';Then use the imported function in your component:<div className={ clsx(classes.class1, classes.class2)}>
Original Link: https://dev.to/himanshupal0001/ways-to-pass-multiple-classes-in-react-p46
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To