Exporting and Importing Components in React
📖 Scenario: You are building a simple React app that shows a greeting message. To keep your code organized, you want to create the greeting message as a separate component and then use it inside your main app component.
🎯 Goal: Build two React components: a Greeting component that shows a message, and an App component that imports and uses the Greeting component.
📋 What You'll Learn
Create a functional React component called
Greeting that returns a <h1> with the text 'Hello, welcome to React!'Export the
Greeting component as a named exportCreate a functional React component called
AppImport the
Greeting component inside App using a named importUse the
<Greeting /> component inside the App component's returned JSX💡 Why This Matters
🌍 Real World
In real React projects, components are split into separate files and imported/exported to keep code clean and maintainable.
💼 Career
Understanding how to export and import components is essential for working on React apps in professional development teams.
Progress0 / 4 steps