🚀 Just built the Tic-Tac-Toe game using React (from the official docs)! This project taught me not only core React concepts but also helped me fix some tricky bugs that improved my understanding. Key Concepts I Learned 🔹 Breaking UI into reusable components (Square, Board) 🔹 Passing data & callbacks using props 🔹 Managing state with useState 🔹 Why immutability matters (slice() before updating) 🔹 Clean one-way data flow from parent → child 🔹 Writing pure helper functions like calculateWinner() 🔹 Conditional rendering for displaying game status Interesting Bugs I Fixed Along the Way 🐞 1. Wrong loop condition (lines[0].length) I mistakenly used lines[0].length instead of lines.length in the winner-checking loop. This caused the winner function to stop early and fail in some cases. Fixing it helped me understand how array-of-arrays work in JavaScript. 🐞 2. Missing <> </> fragment wrapper At one point I didn’t wrap JSX elements inside a fragment, causing compilation errors. This taught me how JSX must always return a single parent element. 🐞 3. Infinite re-render confusion I learned the difference between: ✔ passing a function → onClick={() => handleClick(0)} ✘ calling a function during render → onClick={handleClick(0)} Understanding this removed my confusion about unnecessary re-renders. Overall Takeaway This small project helped me understand how React really works: state updates trigger re-renders, JSX must be well-structured, and immutability + pure functions make the UI predictable. Excited to keep building more projects! ⚡ #react #javascript #webdevelopment #frontenddevelopment #reactjs #learninginpublic #codingjourney #softwareengineering #programming #developers #100daysofcode #projectbasedlearning #webdev

To view or add a comment, sign in

Explore content categories