I need to build a hook to do some generic styles and use it around my project. I tried to do the following:
export const textStyles = () => {
const styles = {
TextMd,
};
return styles;
};
const TextMd: React.FC<{ className: string }> = ({ className }) => {
return (
<p
className={`block transform transition-colors duration-200 py-2 hover:text-gray-800 text-gray-800 .leading-relaxed ${className}`}
></p>
);
};
I use it around like this:
import { textStyles } from '../utils/stiles.tsx'
const { TextMd } = textStyles();
<TextMd>Hello world</TextMd>
Just add the children property
import {ReactNode} from 'react' const TextMd: React.FC<{ className: string, children: ReactNode }> = ({ className, children }) => { return ( <p className={`block transform transition-colors duration-200 py-2 hover:text-gray-800 text-gray-800.leading-relaxed ${className}`} >{children}</p> ); };
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.