Day 26 #100DaysOfCode 💻 Today I learned about Function, Component, State & Event in Next.js. 🔹 Function Functions are reusable blocks of code used to perform specific tasks. 🔹 Component In Next.js, everything is a component. It helps to break UI into reusable pieces. 🔹 State State is used to store dynamic data inside a component and re-render UI when data changes. 🔹 Event Events handle user interactions like clicks, input, form submission, etc. 💻 Code Snippet: "use client"; import { useState } from "react"; export default function Counter() { const [count, setCount] = useState(0); const handleClick = () => { setCount(count + 1); }; return ( <div> <h2>Count: {count}</h2> <button onClick={handleClick}>Increase</button> </div> ); } 🚀 Small reflection: Understanding these core concepts makes building dynamic and interactive apps much easier. #NextJS #ReactJS #WebDevelopment #JavaScript #Frontend #CodingJourney #Akbiplob
Next.js Fundamentals: Function, Component, State & Event
More Relevant Posts
-
🚀 Understanding useEffect in React — Simplified! If you're working with React, mastering useEffect is not optional— 👉 It controls how your app interacts with the outside world. 💡 What is useEffect? useEffect is a hook that lets you perform side effects in components. 👉 Side effects include: API calls Event listeners Timers DOM updates ⚙️ Basic Syntax useEffect(() => { // side effect logic }, [dependencies]); 🧠 How it works 1️⃣ Runs after component renders 2️⃣ Re-runs when dependencies change 3️⃣ Cleanup runs before next effect or unmount 🔹 Example useEffect(() => { console.log("Component mounted or updated"); }, []); 👉 Runs only once (on mount) 🔹 With Dependency useEffect(() => { console.log("Count changed"); }, [count]); 👉 Runs when count changes 🔹 Cleanup Function useEffect(() => { const timer = setInterval(() => { console.log("Running..."); }, 1000); return () => clearInterval(timer); }, []); 👉 Prevents memory leaks 🧩 Real-world use cases ✔ Fetching API data ✔ Subscribing to events ✔ Setting intervals / timeouts ✔ Syncing with external systems 🔥 Best Practices (Most developers miss this!) ✅ Always use dependency array correctly ✅ Cleanup side effects properly ✅ Split multiple effects into separate useEffects ❌ Don’t ignore dependencies (can cause bugs) ❌ Don’t overuse useEffect unnecessarily ⚠️ Common Mistake useEffect(() => { fetchData(); }, []); 👉 If fetchData depends on props/state → can cause bugs 💬 Pro Insight useEffect is not just about running code— 👉 It’s about syncing your component with external systems 📌 Save this post & follow for more deep frontend insights! 📅 Day 13/100 #ReactJS #FrontendDevelopment #JavaScript #ReactHooks #useEffect #WebDevelopment #SoftwareEngineering #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
🤔 useMemo and useCallback confuse almost every React developer. Here’s the clearest way to think about it 👇 🧠 Core idea: → useMemo = cache a VALUE → useCallback = cache a FUNCTION REFERENCE 💻 Example: // useMemo — don't recalculate unless deps change const total = useMemo(() => cart.reduce((sum, item) => sum + item.price, 0), [cart] ); // useCallback — don't recreate unless deps change const handleClick = useCallback(() => { doSomething(id); }, [id]); 🎯 When to use useCallback: When you pass a function to a React.memo’d child Without it 👇 ➡️ A new function is created every render ➡️ React.memo becomes useless ⚠️ Common mistake: Wrapping everything in useMemo / useCallback “just in case” 💡 Reality check: Both hooks have a cost Use them only when: ✔️ You’ve identified a real performance issue ✔️ You’ve actually measured it 📌 Rule: Premature optimization ≠ good engineering #ReactJS #Hooks #JavaScript #FrontendDev
To view or add a comment, sign in
-
🚀 Debounce vs Throttle in React (and when to use each) Handling user interactions efficiently is key to building performant applications — especially when dealing with frequent events like typing and scrolling. Here’s a simple breakdown: 🔹 Debounce • Delays execution until the user stops triggering the event • Best for: search inputs, API calls on typing 🔹 Throttle • Limits execution to once every fixed interval • Best for: scroll events, resize handlers ⚠️ Without control, frequent events can lead to: • Too many API calls • UI lag • Performance issues 📈 Results: • Reduced unnecessary API requests • Improved UI responsiveness • Better user experience 💡 Key takeaway: Use debounce when you want the final action, use throttle when you want continuous control. What scenarios have you used debounce or throttle in? #React #Frontend #WebDevelopment #Performance #JavaScript #NextJS
To view or add a comment, sign in
-
-
Ever clicked two dropdowns and both stayed open at the same time? 😾 Looks unprofessional. Feels broken. Users hate it. Here is how I fixed it in React with just 2 lines : 👉 When Explore opens → force "Degree" dropdown to close onClick={() => { setIsExploreMenuOpen(!isExploreMenuOpen); setIsDegreeMenuOpen(false); // ← this one line does it }} 👉 When Degree opens → force "Explore" dropdown to close onClick={() => { setIsDegreeMenuOpen(!isDegreeMenuOpen); setIsExploreMenuOpen(false); // ← same idea }} The logic is simple: When you open something → explicitly close everything else. React does not do this automatically. You have to tell it exactly what to close. Small detail. Big difference in user experience. #react #nextjs #javascript #webdevelopment #tailwindcss #buildinpublic #frontenddevelopment
To view or add a comment, sign in
-
💡 Mastering useEffect in React — Stop Guessing, Start Understanding If you’ve worked with React, you’ve probably used useEffect… and maybe struggled with it too. Here’s the simple way to think about it: 👉 useEffect lets you run side effects in your components That means anything that interacts outside the React render cycle: - API calls 🌐 - Subscriptions 🔔 - Timers ⏱️ - DOM manipulation 🧩 🔑 The 3 most important patterns: 1] Run once (on mount): useEffect(() => { console.log("Component mounted"); }, []); 2] Run when a dependency changes: useEffect(() => { console.log("Value changed"); }, [value]); 3] Cleanup (avoid memory leaks): useEffect(() => { const timer = setInterval(() => { console.log("Running..."); }, 1000); return () => clearInterval(timer); }, []); ⚠️ Common mistakes to avoid: Forgetting dependencies → leads to stale data bugs Adding unnecessary dependencies → causes infinite loops Ignoring cleanup → memory leaks & performance issues 🧠 Pro tip: If your useEffect feels complicated… it probably is. Try splitting it into smaller effects or rethinking your logic. ✨ useEffect isn’t hard — it’s just misunderstood. Once you get the mental model right, everything clicks. #React #JavaScript #WebDevelopment #Frontend
To view or add a comment, sign in
-
I used to think performance optimization is for advanced developers… So I ignored it. Focused only on building features. But during one project, I noticed: Slow loading Unnecessary re-renders Heavy components That’s when it clicked. 👉 Performance is not optional anymore Now I focus on: • Smaller components • Optimized rendering • Clean logic The biggest learning: A fast app is always better than a complex one. What do you prioritize more: Features or performance? #ReactJS #WebPerformance #FrontendDeveloper #JavaScript
To view or add a comment, sign in
-
Built a to-do app with a glassmorphic UI as a mini project. Kept it simple — vanilla HTML, CSS, and JS. No frameworks. A few things I learned along the way: — Local Storage API to persist tasks on refresh — DOM manipulation with vanilla JS — How CSS backdrop-filter actually works for the glass effect — JSON.stringify and JSON.parse for saving arrays Small project but learned a lot from it. More coming. repo link: https://lnkd.in/dEtj35Us #WebDev #JavaScript #Frontend #BuildInPublic
To view or add a comment, sign in
-
-
I learnt a lot doing this project. Understood the use of React like never before and how certain features are utilized. Features: -> Drag-and-drop tasks across the Todo, Working, Completed columns using a React Library -> Add, edit, and view tasks with modals -> State management using React Context -> Persistent tasks with localStorage -> Learned advanced React hooks, context, and dynamic UI handling This project helped me level up my React skills and understand interactive, state-driven UIs. React Todo Website: https://lnkd.in/eXKm3Hqn Check it out on GitHub: https://lnkd.in/exiv6Tpv #ReactJS #Frontend #WebDevelopment #UIUX #TodoApp #JavaScript
To view or add a comment, sign in
-
My React component was re-rendering again and again… 😅 And then I realized — it’s not random. 💡 In React: A component re-renders when: • State changes • Props change • Parent component re-renders 🧠 Simple example: const [count, setCount] = useState(0); 👉 setCount() → triggers re-render ⚠️ What I was doing wrong: Creating new functions & objects on every render <button onClick={() => handleClick()} /> 👉 New reference every time ❌ 👉 Causes unnecessary re-renders 💡 How I fixed it: • useCallback → memoize functions • React.memo → prevent child re-renders • Avoid inline objects/functions ✅ Result: • Fewer re-renders • Better performance • More predictable UI 🔥 What I learned: React re-renders are predictable 👉 You just need to understand the triggers #ReactJS #FrontendDeveloper #JavaScript #ReactInterview #CodingTips #WebDevelopment
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