Gathering detailed insights and metrics for @kodingdotninja/use-tailwind-breakpoint
Gathering detailed insights and metrics for @kodingdotninja/use-tailwind-breakpoint
Custom hooks to use breakpoints for React 🎐🔨
npm install @kodingdotninja/use-tailwind-breakpoint
Typescript
Module System
Node Version
NPM Version
84.7
Supply Chain
97.2
Quality
78.6
Maintenance
100
Vulnerability
100
License
TypeScript (70.51%)
JavaScript (18.6%)
HTML (7.23%)
CSS (3.67%)
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Total Downloads
329,870
Last Day
2,415
Last Week
11,883
Last Month
47,710
Last Year
249,936
MIT License
65 Stars
19 Commits
5 Forks
3 Watchers
1 Branches
2 Contributors
Updated on Mar 11, 2025
Minified
Minified + Gzipped
Latest Version
1.0.0
Package Id
@kodingdotninja/use-tailwind-breakpoint@1.0.0
Unpacked Size
9.02 kB
Size
3.26 kB
File Count
7
NPM Version
10.5.0
Node Version
20.12.2
Published on
Apr 18, 2024
Cumulative downloads
Total Downloads
Last Day
35.1%
2,415
Compared to previous day
Last Week
16.7%
11,883
Compared to previous week
Last Month
24.6%
47,710
Compared to previous month
Last Year
338.7%
249,936
Compared to previous year
2
Custom hooks to use breakpoints for React 🎐🔨
Table of contents
1pnpm install @kodingdotninja/use-tailwind-breakpoint
Similar to pmndrs/zustand
's create
API, initialize the breakpoint hooks by passing the resolved Tailwind CSS configuration using resolveConfig
:
1// /hooks/tailwind.ts 2 3import { create } from "@kodingdotninja/use-tailwind-breakpoint"; 4import resolveConfig from "tailwindcss/resolveConfig"; 5 6import tailwindConfig from "path/to/tailwind.config.js"; 7 8const config = resolveConfig(tailwindConfig); 9 10export const { useBreakpoint } = create(config.theme.screens);
screens
valuesAnother option is to extract all screens
values into a separate file:
1// tailwind.screens.js or other name to separate breakpoint values 2const screens = { 3 sm: "640px", 4 md: "768px", 5 // ... 6};
To keep the same values, require
inside tailwind.config.js
:
1// tailwind.config.js 2module.exports = { 3 theme: { 4 screens: require("path/to/tailwind.screens.js"), 5 }, 6 // ... 7};
Then pass the extracted screens
to the create
function:
1// /hooks/tailwind.ts 2 3import { create } from "@kodingdotninja/use-tailwind-breakpoint"; 4 5import screens from "path/to/tailwind.screens.js"; 6 7export const { useBreakpoint } = create(screens);
While this package was built in mind for Tailwind CSS usage, it can be used without it since there is no dependency at all. You can pass any breakpoint values:
1// /hooks/breakpoint.ts 2 3import create from "@kodingdotninja/use-tailwind-breakpoint"; 4 5export const { useBreakpoint } = create({ 6 sm: "640px", 7 md: "768px", 8 // ... 9});
useBreakpoint()
Use breakpoint value from given breakpoint token
1import { useBreakpoint } from "./lib/tailwind"; 2 3function App() { 4 const isDesktop = useBreakpoint("md"); 5 6 return <div>Current view: {isDesktop ? "Desktop" : "Mobile"}</div>; 7}
useBreakpointEffect()
Use given breakpoint value to run an effect
1import { useBreakpointEffect } from "./lib/tailwind"; 2 3function App() { 4 useBreakpointEffect("md", (match) => { 5 if (match) { 6 console.log("Desktop view"); 7 } 8 }); 9}
useBreakpointValue()
Resolve value from given breakpoint value
1import { useBreakpointValue } from "./lib/tailwind"; 2 3function App() { 4 const value = useBreakpointValue("md", "Desktop", "Mobile"); 5 6 return <div>Current view: {value}</div>; 7}
No vulnerabilities found.
No security vulnerabilities found.