💭 Ever wished window.confirm() could show your own custom modal? I did — and got tired of juggling modal states, callbacks, and context just to ask: “Are you sure?” So I built a small helper for myself… and figured others might find it useful too 👇 👉 @sghere/react-confirm A minimal, promise-based confirm utility for React — lightweight, zero-config, and works beautifully with your own UI. ✨ Features 🧩 Zero configuration — works out of the box ⚛️ Fully compatible with React 16+ and 18 💬 Promise-based API: await confirm({...}) 🧠 Type-safe with ConfirmOptions support 🎨 Tailwind-ready styling — easily themeable 🪶 Lightweight — under 5 KB gzipped 📦 Installation npm install @sghere/react-confirm # or yarn add @sghere/react-confirm # or bun add @sghere/react-confirm ⚠️ Requires react and react-dom as peer dependencies 🚀 Quick Start import { confirm } from "@sghere/react-confirm"; import "@sghere/react-confirm/dist/react-confirm.css"; <button onClick={() => { confirm({ heading: "Are you sure?", body: "This will be deleted", onConfirm: () => { alert("Deleted ✅"); }, }); }} > Delete Item </button> It’s a small utility — nothing fancy — but it’s made my workflow cleaner and faster. If you give it a try, I’d love your thoughts or suggestions to make it better 🙌 #React #OpenSource #Frontend #JavaScript #ReactJS #WebDev #DeveloperTools #DevCommunity
"Introducing @sghere/react-confirm: A lightweight, zero-config confirm utility for React"
More Relevant Posts
-
💡React Tip💡 You don't need to use debouncing every time during search or filtering. React 18's useTransition hook offers a more seamless way to manage them. ⚡ 𝗪𝗵𝘆 𝗶𝘁'𝘀 𝗽𝗼𝘄𝗲𝗿𝗳𝘂𝗹: → Keeps your UI responsive during heavy updates → No need for setTimeout or debounce libraries → Built-in priority system for React rendering → Perfect for search filters, data tables, and complex lists 𝗧𝗵𝗲 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: When filtering large lists, every keystroke can freeze your UI because React tries to update everything immediately. 𝗦𝗼𝗹𝘂𝘁𝗶𝗼𝗻: use useTransition hook from react. useTransition lets you mark certain updates as "low priority" so React can keep your UI smooth. In the code sample example, typing in the search box updates instantly (high priority), while filtering the huge list happens in the background (low priority) without blocking the input. The isPending flag tells you when the background work is still running, so you can show a loading indicator. 𝗞𝗲𝘆 𝗕𝗲𝗻𝗲𝗳𝗶𝘁𝘀: → Input stays responsive - no lag while typing → React automatically prioritizes user input over list updates → isPending gives you a loading state for free → Works seamlessly with Suspense boundaries 𝗖𝗵𝗲𝗰𝗸 𝗼𝘂𝘁 𝘁𝗵𝗲 𝗦𝘁𝗮𝗰𝗸𝗯𝗹𝗶𝘁𝘇 𝗱𝗲𝗺𝗼 𝗹𝗶𝗻𝗸 𝗶𝗻 𝘁𝗵𝗲 𝗰𝗼𝗺𝗺𝗲𝗻𝘁 𝘁𝗼 𝘀𝗲𝗲 𝗶𝘁 𝗶𝗻 𝗮𝗰𝘁𝗶𝗼𝗻. 𝘍𝘰𝘳 𝘮𝘰𝘳𝘦 𝘴𝘶𝘤𝘩 𝘶𝘴𝘦𝘧𝘶𝘭 𝘤𝘰𝘯𝘵𝘦𝘯𝘵, 𝘥𝘰𝘯'𝘵 𝘧𝘰𝘳𝘨𝘦𝘵 𝘵𝘰 𝘧𝘰𝘭𝘭𝘰𝘸 𝘮𝘦. #javascript #reactjs #nextjs #webdevelopment
To view or add a comment, sign in
-
-
𝐇𝐨𝐰 𝐈𝐦𝐦𝐞𝐫 𝐏𝐨𝐰𝐞𝐫𝐬 𝐈𝐦𝐦𝐮𝐭𝐚𝐛𝐢𝐥𝐢𝐭𝐲 𝐢𝐧 𝐑𝐞𝐝𝐮𝐱 𝐓𝐨𝐨𝐥𝐤𝐢𝐭 — 𝐖𝐢𝐭𝐡𝐨𝐮𝐭 𝐭𝐡𝐞 𝐏𝐚𝐢𝐧 🧠 𝐄𝐯𝐞𝐫 𝐰𝐨𝐧𝐝𝐞𝐫𝐞𝐝 𝐰𝐡𝐲 𝐑𝐞𝐝𝐮𝐱 𝐓𝐨𝐨𝐥𝐤𝐢𝐭 𝐥𝐞𝐭𝐬 𝐲𝐨𝐮 “𝐦𝐮𝐭𝐚𝐭𝐞” 𝐬𝐭𝐚𝐭𝐞 — 𝐛𝐮𝐭 𝐬𝐭𝐢𝐥𝐥 𝐬𝐭𝐚𝐲𝐬 𝐢𝐦𝐦𝐮𝐭𝐚𝐛𝐥𝐞? That magic comes from a brilliant library called Immer — one of the most underrated algorithmic ideas in modern frontend development. ⚙️ 𝐓𝐡𝐞 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐁𝐞𝐟𝐨𝐫𝐞 𝐈𝐦𝐦𝐞𝐫 Classic Redux forced us to write immutable updates manually: return { ...state, user: { ...state.user, name: action.payload } }; Lots of boilerplate. Lots of bugs. 😩 🌱 𝐄𝐧𝐭𝐞𝐫 𝐈𝐦𝐦𝐞𝐫 Immer flips that problem. It lets you write mutable-looking code, but it creates immutable copies behind the scenes. const slice = createSlice({ name: "counter", initialState: { value: 0 }, reducers: { increment(state) { state.value += 1; // looks mutable 👀 } } }); Under the hood, Redux Toolkit uses Immer’s copy-on-write algorithm to keep state immutable. 🧩 𝐇𝐨𝐰 𝐈𝐦𝐦𝐞𝐫 𝐖𝐨𝐫𝐤𝐬 1️⃣ Proxy Drafts: Wraps state in a JavaScript Proxy — intercepts reads/writes. 2️⃣ Track Changes: Only records modified paths. 3️⃣ Finalize: Copies changed objects, reuses unchanged ones, and produces a new immutable tree. This is called structural sharing — the same principle that powers React’s fast updates. ⚡ 𝐖𝐡𝐲 𝐈𝐭’𝐬 𝐁𝐫𝐢𝐥𝐥𝐢𝐚𝐧𝐭 ✅ Zero boilerplate ✅ Immutable state by default ✅ Fast and safe updates ✅ Perfect fit for Redux Toolkit In short: Immer made Redux fun again. 🎉 💡 𝐅𝐢𝐧𝐚𝐥 𝐓𝐡𝐨𝐮𝐠𝐡𝐭 Next time you call state.value += 1, remember — you’re writing mutable code, but Redux stays immutable, thanks to Immer’s elegant algorithmic design. #Redux #Immer #ReduxToolkit #JavaScript #ReactJS #Frontend #WebDevelopment #SoftwareEngineering #CodingTips
To view or add a comment, sign in
-
🚀 𝗟𝗲𝘃𝗲𝗹 𝗨𝗽 𝗬𝗼𝘂𝗿 𝗥𝗲𝗮𝗰𝘁 𝗖𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁𝘀 𝘄𝗶𝘁𝗵 𝗛𝗶𝗴𝗵𝗲𝗿-𝗢𝗿𝗱𝗲𝗿 𝗖𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁𝘀 (𝗛𝗢𝗖𝘀)! 🚀 Ever catch yourself writing the same logic across multiple React components? That’s where 𝗛𝗶𝗴𝗵𝗲𝗿-𝗢𝗿𝗱𝗲𝗿 𝗖𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁𝘀 (𝗛𝗢𝗖𝘀) come in. HOCs are one of React’s most powerful patterns for 𝗿𝗲𝘂𝘀𝗶𝗻𝗴 𝗰𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁 𝗹𝗼𝗴𝗶𝗰 and keeping your codebase clean and maintainable. 🔍 𝗪𝗵𝗮𝘁 𝗶𝘀 𝗮 𝗛𝗢𝗖? A 𝗛𝗶𝗴𝗵𝗲𝗿-𝗢𝗿𝗱𝗲𝗿 𝗖𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁 is simply a function that takes a component and returns a new one with extra props or behavior. It’s like a 𝗱𝗲𝗰𝗼𝗿𝗮𝘁𝗼𝗿 for your components, wrapping them to add new capabilities without changing their core. 💡 𝗪𝗵𝘆 𝗨𝘀𝗲 𝗛𝗢𝗖𝘀? ✅ 𝗖𝗼𝗱𝗲 𝗥𝗲𝘂𝘀𝗮𝗯𝗶𝗹𝗶𝘁𝘆 Extract shared logic like authentication, data fetching, or logging so you don’t repeat code everywhere. ✅ 𝗦𝗲𝗽𝗮𝗿𝗮𝘁𝗶𝗼𝗻 𝗼𝗳 𝗖𝗼𝗻𝗰𝗲𝗿𝗻𝘀 Let your components focus on rendering UI while HOCs handle business logic behind the scenes. ✅ 𝗣𝗿𝗼𝗽𝘀 𝗠𝗮𝗻𝗶𝗽𝘂𝗹𝗮𝘁𝗶𝗼𝗻 Easily inject or modify props to make your components more flexible and dynamic. Even though 𝗵𝗼𝗼𝗸𝘀 like 𝘶𝘴𝘦𝘊𝘰𝘯𝘵𝘦𝘹𝘵 and 𝗰𝘂𝘀𝘁𝗼𝗺 𝗵𝗼𝗼𝗸𝘀 are the go-to solution in modern React, HOCs still shine in large-scale applications and class component architectures. They’re especially useful when you want to extend functionality across multiple components without rewriting logic. Have you used HOCs in your projects? Or do you prefer other patterns like Render Props or Custom Hooks? 💬 Comment 𝗛𝗢𝗖 below and share your favorite use case or pattern that helps you write smarter React components! #React #ReactJS #HigherOrderComponents #FrontendDevelopment #SoftwareArchitecture #DesignPatterns #JavaScript #WebDevelopment #DeveloperCommunity #TechTalk
To view or add a comment, sign in
-
-
Great explanation! In Angular, we often handle similar logic through services or directives, but it’s really interesting to see how React uses HOCs to achieve the same level of reusability and separation of concerns.
🚀 𝗟𝗲𝘃𝗲𝗹 𝗨𝗽 𝗬𝗼𝘂𝗿 𝗥𝗲𝗮𝗰𝘁 𝗖𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁𝘀 𝘄𝗶𝘁𝗵 𝗛𝗶𝗴𝗵𝗲𝗿-𝗢𝗿𝗱𝗲𝗿 𝗖𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁𝘀 (𝗛𝗢𝗖𝘀)! 🚀 Ever catch yourself writing the same logic across multiple React components? That’s where 𝗛𝗶𝗴𝗵𝗲𝗿-𝗢𝗿𝗱𝗲𝗿 𝗖𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁𝘀 (𝗛𝗢𝗖𝘀) come in. HOCs are one of React’s most powerful patterns for 𝗿𝗲𝘂𝘀𝗶𝗻𝗴 𝗰𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁 𝗹𝗼𝗴𝗶𝗰 and keeping your codebase clean and maintainable. 🔍 𝗪𝗵𝗮𝘁 𝗶𝘀 𝗮 𝗛𝗢𝗖? A 𝗛𝗶𝗴𝗵𝗲𝗿-𝗢𝗿𝗱𝗲𝗿 𝗖𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁 is simply a function that takes a component and returns a new one with extra props or behavior. It’s like a 𝗱𝗲𝗰𝗼𝗿𝗮𝘁𝗼𝗿 for your components, wrapping them to add new capabilities without changing their core. 💡 𝗪𝗵𝘆 𝗨𝘀𝗲 𝗛𝗢𝗖𝘀? ✅ 𝗖𝗼𝗱𝗲 𝗥𝗲𝘂𝘀𝗮𝗯𝗶𝗹𝗶𝘁𝘆 Extract shared logic like authentication, data fetching, or logging so you don’t repeat code everywhere. ✅ 𝗦𝗲𝗽𝗮𝗿𝗮𝘁𝗶𝗼𝗻 𝗼𝗳 𝗖𝗼𝗻𝗰𝗲𝗿𝗻𝘀 Let your components focus on rendering UI while HOCs handle business logic behind the scenes. ✅ 𝗣𝗿𝗼𝗽𝘀 𝗠𝗮𝗻𝗶𝗽𝘂𝗹𝗮𝘁𝗶𝗼𝗻 Easily inject or modify props to make your components more flexible and dynamic. Even though 𝗵𝗼𝗼𝗸𝘀 like 𝘶𝘴𝘦𝘊𝘰𝘯𝘵𝘦𝘹𝘵 and 𝗰𝘂𝘀𝘁𝗼𝗺 𝗵𝗼𝗼𝗸𝘀 are the go-to solution in modern React, HOCs still shine in large-scale applications and class component architectures. They’re especially useful when you want to extend functionality across multiple components without rewriting logic. Have you used HOCs in your projects? Or do you prefer other patterns like Render Props or Custom Hooks? 💬 Comment 𝗛𝗢𝗖 below and share your favorite use case or pattern that helps you write smarter React components! #React #ReactJS #HigherOrderComponents #FrontendDevelopment #SoftwareArchitecture #DesignPatterns #JavaScript #WebDevelopment #DeveloperCommunity #TechTalk
To view or add a comment, sign in
-
-
⚛️ A small React concept that makes a big difference — Custom Hooks Ever noticed how Components start getting messy when they handle too much state or logic? ✅ Api Calls ✅ Toggles ✅ Timers ✅ Scroll or Resize Listeners ✅ Form Logic Instead of repeating the same code everywhere, just extract it into a Custom hook. Cleaner components, Reusable logic, Fewer bugs. e.g.: function useToggle(initial = false) { const [value, setValue] = useState(initial); const toggle = () => setValue(v => !v); return [value, toggle]; } // const [open, toggleOpen] = useToggle(); Suddenly your component becomes lighter, readable, and scalable. You can combine multiple hooks and get a polished UI without clutter. If you're a beginner: ➡️ Learn custom hooks early ➡️ Your future self will thank you What’s the coolest custom hook you’ve built or used recently? 🚀 #reactjs #javascript #frontend #webdev #reacthooks #cleancode #programmingtips #buildinpublic
To view or add a comment, sign in
-
🧩 Custom Hooks: The Hidden Superpower of React When React introduced hooks, it wasn’t just another API — it was a quiet revolution. ⚡ Before hooks, we wrote class components that grew like wild forests. Logic was tangled across lifecycles, duplicated, or hidden behind HOCs. Then came this little thing called useSomething(). Suddenly, we could extract logic like Lego blocks. 💡 The moment I truly understood React wasn’t when I learned useEffect. It was when I realized I could write my own. function useOnlineStatus() { const [isOnline, setIsOnline] = useState(navigator.onLine); useEffect(() => { const updateStatus = () => setIsOnline(navigator.onLine); window.addEventListener('online', updateStatus); window.addEventListener('offline', updateStatus); return () => { window.removeEventListener('online', updateStatus); window.removeEventListener('offline', updateStatus); }; }, []); return isOnline; } That’s not a utility — that’s architecture in disguise. Hooks make behavior composable, predictable, and testable. The biggest mistake developers make? Using built-in hooks forever but never writing their own. Once you start thinking in custom hooks, you stop building components — and start designing systems of logic. #ReactJS #Hooks #FrontendDevelopment #CleanCode #JavaScript #WebArchitecture #ReactDesignPatterns #SystemDesign
To view or add a comment, sign in
-
⚛️ React Just Made Form Actions Way Cleaner React’s new hook — useActionState — is a game-changer for handling async form submissions. No more juggling useState, useEffect, or endless try/catch blocks. 🙌 Here’s what it does 👇 🧩 You pass it: A form action (e.g., addToCart) An initial state It gives you back three things: 1️⃣ The latest state (e.g., message or result) 2️⃣ A wrapped action (formAction) 3️⃣ A flag showing if it’s still running (isPending) Now your form logic becomes simpler, more declarative, and easier to read. Just write the action, hook it up, and React handles the rest. It’s a small addition but one that makes a big difference in building clean, async-ready UIs. ⚡ 💬 Have you tried useActionState yet? What’s your take on React’s direction with these new declarative patterns? #ReactJS #JavaScript #WebDevelopment #Frontend #ReactHooks #CleanCode #AsyncProgramming #DeveloperExperience #SoftwareEngineering #CodingTips #ReactDevelopers #DevCommunity #UIUX
To view or add a comment, sign in
-
-
Custom Hooks in React 🔁 If you’ve worked with React, you already know how powerful built-in hooks like useState and useEffect are. But the real magic begins when you start creating your own custom hooks. Custom hooks allow developers to extract and reuse logic across different components. Instead of repeating the same logic in multiple places, you can simply wrap it inside a custom hook — keeping your code clean, modular, and easier to maintain. 💡 Why use Custom Hooks? Reuse complex logic across components Keep components focused purely on UI Improve readability and scalability Simplify debugging and testing For example, you could create custom hooks for things like API fetching, managing authentication, handling dark mode, or tracking window size. In short, custom hooks bring structure and reusability to your React applications — turning repetitive patterns into elegant, maintainable code. #React #WebDevelopment #Frontend #JavaScript #Coding #Hooks #CustomHooks #TechLearning #ReactJS #stemup
To view or add a comment, sign in
-
🚀 React 19.2 just made forms feel… modern. One of the coolest new things is built-in form actions. Now you can handle form submissions without useState, useEffect, or tons of boilerplate. That means: ✅ less code ✅ fewer bugs ✅ cleaner async logic Here’s the vibe 👇 <form action={async (formData) => { const res = await fetch('/api/send', { method: 'POST', body: formData, }) }}> <input name="email" placeholder="Enter your email" /> <button type="submit">Subscribe</button> </form> That’s it — no state, no handlers, no custom hooks. React automatically handles submission, loading, and even errors — while keeping the UI responsive. In 2025, this feels like React finally catching up with how we actually build products — fast, declarative, and server-first. #React #Frontend #JavaScript #Nextjs #WebDevelopment #React19
To view or add a comment, sign in
-
I finally understood what a Config-Driven UI actually means — and why it’s such a game changer. ⚙️ A lot of people say, “this website is data-driven” or “config-driven,” but I always wondered — aren’t all websites driven by data anyway? Turns out… not really. There’s a small but powerful difference 👇 #ReactJS #Frontend #WebDevelopment #JavaScript #CleanCode #LearningInPublic
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
🔥