How to access Tailwind breakpoints/screens from React #3822
-
I'd like to be able to "react" to breakpoint changes in my app, and I would like those breakpoints to equal the ones configured in Tailwind. I can use Is there a "best practice" way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
If you're using the default screen sizes, you can import them: const defaultTheme = require('tailwindcss/defaultTheme');
console.log(defaultTheme.screens); If you've customized them, you can import your config: const customConfig = require('./tailwind.config');
console.log(customConfig.theme.screens); |
Beta Was this translation helpful? Give feedback.
-
Here's what I wrote in Typescript that returns the current breakpoint based on device width. You can place it in a standalone file and import the methods whenever needed in any file: import resolveConfig from 'tailwindcss/resolveConfig'; const fullConfig = resolveConfig(tailwindConfig); export const getBreakpointValue = (value: string): number => export const getCurrentBreakpoint = (): string => { |
Beta Was this translation helpful? Give feedback.
If you're using the default screen sizes, you can import them:
If you've customized them, you can import your config: