🚨 A small TypeScript mistake I still see in React projects Many developers type their state setters as - (val: number) => void. It looks correct - but it silently breaks a core React feature. React state setters don't just accept a value - they also accept a function. This is essential when your next state depends on the previous one. If you type the setter wrong, functional updates won't typecheck. You've locked yourself out of a feature React gives you for free - and opened the door to subtle bugs. Typing setters correctly means: React's full API stays intact, refactors are safer across your codebase, and state bugs from stale closures become much harder to introduce. It's one line of types. But in a large codebase, it's the difference between code that works and code that works until it doesn't. If you use TypeScript with React, don't throw this away. #TypeScript #React #JavaScript #Frontend #CodingTips
Typing React State Setters Correctly with TypeScript
More Relevant Posts
-
Are you a beginner React developers, wanting to build solid foundation? This is a good resource from Carl Rippon to learn modern React from scratch. It teaches almost all the concepts which matter in 2026 such as, 1. TypeScript 2. React Hooks 3. State management 4. Reusable components 5. Server-side components and rendering 6. React component styling approaches such as Tailwind, CSS-in-JS. 7. Server and client data fetching and mutations 8. Forms 9. Unit testing and more. So, I will highly recommended this resource for beginners. Which resource do you refer to as a React beginners? #react #javascript #frontend
To view or add a comment, sign in
-
-
🚀 Exploring Bun.js – The Fast All-in-One JavaScript Runtime Recently I started experimenting with Bun.js, and honestly it feels like a huge step forward for the JavaScript ecosystem. Instead of using multiple tools like npm, jest, webpack, and node separately, Bun.js combines everything into one runtime. ⚡ Super fast runtime 📦 Built-in package manager 🧪 Native test runner 🔧 Bundler included 🌐 Node.js compatible APIs Quick example: bun create next-app myapp bun install bun run dev Simple. Fast. Powerful. if you want to explore it: 👉 https://bun.com/ As developers, tools that improve performance and developer experience can make a huge difference in how we build modern applications. Have you tried Bun.js yet? Would you consider using it in production? 👇 Share your thoughts. #bunjs #javascript #reactjs #nodejs #webdevelopment #fullstackdeveloper #softwaredevelopment #coding #developers #techcommunity
To view or add a comment, sign in
-
-
When building reusable React components with TypeScript, a common trap is making conflicting props optional. For example, a <Button /> component shouldn't be allowed to have both primary and destructive boolean flags set to true simultaneously. Instead of relying on runtime checks, use Discriminated Unions to catch impossible states at compile time. // ❌ The Anti-Pattern (Allows impossible states) type ButtonProps = { primary?: boolean; destructive?: boolean; label: string; }; // ✅ The Senior Pattern (Mutually exclusive props) type BaseProps = { label: string }; type PrimaryButton = BaseProps & { variant: 'primary' }; type DestructiveButton = BaseProps & { variant: 'destructive'; confirmText: string }; type ButtonProps = PrimaryButton | DestructiveButton; Now, if a developer types variant="destructive", TypeScript will force them to also provide confirmText, and prevents them from mixing up styles. #TypeScript #ReactJS #CleanCode #FrontendDev #WebDevelopment"
To view or add a comment, sign in
-
-
🟢 🟡 🔵 Most developers use JSX every day! but few truly understand what happens behind the scenes. JSX is not HTML inside JavaScript — it’s syntactic sugar that gets transpiled into React.createElement() calls before your app even runs. Why does this matter? Because once you understand this pipeline, you can: ✅ Debug rendering issues faster ✅ Write more predictable components ✅ Avoid common misconceptions about the Virtual DOM Mastering fundamentals like JSX is what separates React users from React engineers. What was your biggest JSX misconception when you started? #React #Frontend #WebDevelopment #JavaScript #SoftwareEngineering
To view or add a comment, sign in
-
-
When I first started learning React, I thought writing more code meant building better features. Turns out… the opposite is often true. One small thing that changed the way I write components: Break large components into smaller reusable ones. Instead of this: function Dashboard() { return ( <div> <Header /> <Sidebar /> <UserStats /> <RecentActivities /> <Notifications /> </div> ) } Think in reusable pieces: StatsCard ActivityItem NotificationItem This makes your code: ✅ Easier to maintain ✅ Easier to reuse ✅ Easier for teammates to understand Clean code isn’t about writing more code. It’s about writing code that future-you will thank you for. Curious 👇 What’s one React concept that confused you when you first learned it? #ReactJS #FrontendDevelopment #WebDevelopment #NextJS #JavaScript #CodingJourney
To view or add a comment, sign in
-
React JS Hooks changed the way we build modern applications. 💙⚛️ As a Full Stack Developer, mastering hooks completely transformed how I think about state, performance, and component architecture. From: 🔹 useState – Managing local state 🔹 useEffect – Handling side effects 🔹 useContext – Avoiding prop drilling 🔹 useReducer – Managing complex state logic 🔹 useMemo & useCallback – Performance optimization 🔹 useRef – Direct DOM access 🔹 useTransition & useDeferredValue – Better UI responsiveness Hooks are not just functions — they’re architectural tools. When you truly understand hooks: ✔ Your components become cleaner ✔ Your state management becomes predictable ✔ Your performance improves ✔ Your code becomes scalable React isn’t about writing components anymore. It’s about designing systems with hooks. If you're learning React in 2026, don’t just memorize hooks — understand when and why to use them. That’s where real growth happens. 🚀 #FullStackDeveloper #ReactJS #FrontendDevelopment #WebDevelopment #JavaScript #SoftwareEngineering
To view or add a comment, sign in
-
-
When I started writing React, I genuinely thought more components = better code. So I broke everything down. Forms, labels, error messages each one its own file. My folder structure looked impressive. My brain hurt trying to debug it. Nobody told me I was solving a problem that didn't exist yet. The shift happened when I actually shipped something and had to live with the code for weeks. Not read about it. Not watch someone refactor it on YouTube. Just... sit with it, confused, until things started making sense. What I figured out slowly: a component isn't about cleanliness. It's about responsibility. One reason to exist. That's it. Once I started asking "does this actually need to be separate?" instead of "can I make this reusable?" things got simpler. Not more sophisticated. Just simpler. The uncomfortable part is that you have to let things be messy first. Let the duplication stay. Let the file grow past what feels acceptable. The real boundaries don't show up until the code tells you where they are and it won't tell you on day one. I still catch myself over-abstracting. Probably always will. But now I at least notice when I'm doing it for my own satisfaction vs. because the code actually needs it. Build the thing. Sit with it. Refactor when it genuinely hurts. That order matters more than any pattern or principle I've read about. #ReactJS #Frontend #WebDevelopment #JavaScript #ComponentArchitecture #SoftwareEngineering #DevJourney
To view or add a comment, sign in
-
Today I revisited an important concept in React.js — the Component Lifecycle. Understanding the lifecycle of a component is essential for writing efficient and maintainable React applications. Every React component goes through a series of phases during its lifetime. Key Lifecycle Phases: • Mounting – When the component is created and inserted into the DOM. • Updating – When the component re-renders due to changes in state or props. • Unmounting – When the component is removed from the DOM. In traditional Class Components, lifecycle methods such as componentDidMount, componentDidUpdate, and componentWillUnmount were used to manage these phases. With Functional Components and React Hooks, particularly useEffect(), managing lifecycle-related logic has become simpler and more readable. Mastering the React lifecycle helps developers: ✔ Handle side effects like API calls ✔ Optimize component performance ✔ Write cleaner and more predictable code Learning React is not only about building components, but also about understanding how they behave throughout their lifecycle. #ReactJS #FrontendDevelopment #JavaScript #WebDevelopment #ReactLifecycle #ReactHooks #SoftwareEngineering #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