React beginner mistake: Wrapping JSX elements in a parent tag

🤦♀️ A classic React beginner mistake I’ll never forget! I was happily building a React component and wrote something like this: function Profile() { return ( <h1>Welcome Back!</h1> <p>Have a great day ahead!</p> ); } But React immediately threw an error: “Adjacent JSX elements must be wrapped in an enclosing tag.” At first, I thought something was wrong with my syntax… Then I learned an important React rule — All return statements must be wrapped inside a single parent element (like a <div> or <React.Fragment>). ✅ Correct version: function Profile() { return ( <div> <h1>Welcome Back!</h1> <p>Have a great day ahead!</p> </div> ); } It’s a simple rule, but it taught me how React compiles JSX and why every component needs a clear structure. One missing <div> — one big lesson learned! 😂 #ReactJS #WebDevelopment #MERNStack #FrontendDeveloper #CodingJourney #LearningByDoing #ReactTips

To view or add a comment, sign in

Explore content categories