I have a react component with fairly complicated design, styled by tailwind and want to make it reusable with different styles depending on the value of its parameter which called variant.
what is the best practice in this situation?
1- make a general class then add different css classes in @layer components, one class for each design.
2- change the style directly in the react component using twMerge and clsx depending on the parameter which i mentioned earlier.
3- use styled-components with tailwindCss
what is the best pracitse to make reusable react component with different styles using tailwind?
320 Views Asked by Lana Hanna At
1
There are 1 best solutions below
Related Questions in REACTJS
- ussd reader in Recket Native module
- Teams tab application returns SSO error in mobile Outlook
- Github Pages Deployment deploys a blank page
- Is there any way to glow this bulb image like a real light bulb
- Optimize LCP ReactJs
- Page in React only renders elements after refreshing
- Unable to Post Form Data to MongoDB because of picturepath
- MERN Stack App - User Avatar Upload - 500 Error After Deployment on Render
- Hooks are not supported inside an async component error in nextjs project using useQuery
- How to change the Font Weight of a SelectValue component in React when a SelectItem is selected?
- On the server side, it returns undefined but on the client side, logs the values no problem
- Multilevel dropdown with checkboxes in Select component
- TypeScript Error only on big type only when assigned to a variable
- Deployment through app engine, cloud sql database, problem connecting with server code, doesn't connect
- Data is not filtering in props. Showing passdata.map is not a function
Related Questions in TAILWIND-CSS
- General questions about creating a custom theme Moodle CMS
- Vue/TailwindCSS - Content is behind Sidebar
- 'bun' is not recognized as an internal or external command
- Trouble generating PDFs with Playwright in Docker container
- tailwind CSS applied on react component moves the navigation bar along in remix
- Is there a way to support Tailwind @apply in Visual Studio?
- Flex layout with grid system in tailwind
- How do I integrate an existing delete function that is located in my routes.php file to a delete button in a modal in my hr.employees.profile.php?
- How can i prevent the image from zooming in when i resize the browser?
- Tailwind CSS background image does not work on github pages
- How to achieve this with chart.js in react?
- What other ways to get my expo go to load?
- Tailwind.css in Remix project does not load file or styles
- Tailwind would not load in a new nextjs app... Unexpected character '@'
- Web server doesnt output the website like in the project on localhost
Related Questions in STYLED-COMPONENTS
- Migrate from Babel to Nextjs SWC encountering Minified React error
- Global CSS is not properly loading with SSG in Next JS - CORS error?
- OutlineTextField text not changed
- CSS properties with conditional styles and falsy values
- NextJS shows Warning: Prop className did not match when using Tailwind CSS and styled components
- Css properties as falsie values in react
- How to use component prop with custom components based on Material UI (with emotion)?
- "TypeError: t is not a function" while working with updating the `react-data-table-component` package
- Can't see tag suggestions after importing styled-components
- Progress Bar styling with styled components - React/TypeScript
- antd scrollbar always visibile (problem on firefox)
- CSS Conditional styling if Component is of max-width: 600px
- Trouble rendering "styled-components/native" with "react-native-web" in React Native (CLI) project for Web
- keyframes animation (Invalid value for prop) error with typescript +react + styled component
- React - Highcharts Chart will enlarge but wont shrink
Related Questions in CLSX
- Using clsx library for conditional CSS class composition, but getting unexpected behaviour
- Click and display child component delay/animation in React
- How to dynamically align FullCalendar event title in Typescript with Next JS?
- What's the syntax of clsx to add two classNames when one condition satisfied?
- Conditional CSS class fix
- How to use Tailwind colors in custom background linear-gradient rule with tailwind-merge?
- CLSX shadow stacking in React
- what is the best pracitse to make reusable react component with different styles using tailwind?
- Can't build className dinamically using clsx and Tailwind
- Converting a React component to Typescript Element implicitly has an 'any' type because expression of type 'string | number' can't be used to index
- Button component prop to change className overrides the default value?
- Unable to make a transition for Dropdown
- How do you use a fallback class for clsx to prevent Typescript complaining?
- React & clsx: add a class name if the current item in a mapped array is the first of multiple items
- Create a styling rule for clsx for React + Typescript
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
This is the way I like to do it as it's clean.
You can also add this to your VSCode settings if you'd like to have intellisense for custom classes. It works by detecting anything ending in 'classes' as Tailwind styles.
`
Create a component