Rendering Multiple Elements in React JS – Detailed Notes
Rendering Multiple Elements in React JS means displaying multiple HTML elements, JSX elements, or React components together in a user interface. React allows developers to combine headings, paragraphs, images, buttons, lists, and reusable components to create complete web pages.
To render multiple elements in React, developers commonly use a parent element, React Fragments, arrays of JSX elements, reusable components, and JavaScript's map() method. Understanding these techniques helps create clean, organized, and reusable React applications.
1. What Is Rendering Multiple Elements?
Rendering multiple elements means displaying more than one element within a React component. For example, a page might contain a heading, a paragraph, an image, and a button.
Example:
function App() {
return (
<div>
<h1>Welcome to React JS</h1>
<p>Learn how to build web applications.</p>
<button>Get Started</button>
</div>
);
}
export default App;
Explanation:
div is the parent element.
h1 displays the main heading.
p displays a paragraph.
button displays an interactive button.
The component returns one root JSX element, which contains multiple child elements.
2. Why Is Rendering Multiple Elements Important?
Most real-world interfaces require multiple elements to work together. Rendering multiple elements makes it possible to organize content into meaningful sections.
- Page layouts: Combine headers, navigation bars, main content, and footers.
- Forms: Display labels, input fields, validation messages, and buttons.
- Product cards: Display images, names, prices, descriptions, and purchase buttons.
- Dashboards: Display charts, statistics, tables, and notifications.
- Lists: Display collections of students, employees, products, or courses.
- Reusable UI: Combine multiple React components to build larger interfaces.
3. Rendering Multiple Elements Using a Parent Element
The simplest way to return multiple JSX elements is to wrap them inside one parent element, such as div, section, main, or article.
Syntax:
function Component() {
return (
<parentElement>
<ElementOne />
<ElementTwo />
<ElementThree />
</parentElement>
);
}
Example:
function App() {
return (
<section>
<h1>About Our Academy</h1>
<p>We provide technology training courses.</p>
<a href="https://example.com">Learn More</a>
</section>
);
}
Advantages:
- Easy to understand and maintain.
- Creates a clear structure for related content.
- Allows CSS styles to be applied to the parent container.
- Works well for sections, cards, and page layouts.
Limitation: An extra parent element becomes part of the rendered DOM. This can sometimes affect styling or the structure required by elements such as tables.
4. Rendering Multiple Elements Using React Fragments
A React Fragment groups multiple JSX elements without adding an extra DOM element. Fragments are useful when you need a single JSX root but do not want an additional div or other wrapper in the rendered HTML.
React supports two common Fragment syntaxes: the shorthand syntax and the explicit Fragment component.
4.1 Fragment Shorthand Syntax
The shorthand syntax uses an empty opening and closing tag: <>...>.
Example:
function App() {
return (
<>
<h1>React JS Training</h1>
<p>Learn React fundamentals.</p>
<button>Explore Course</button>
</>
);
}
export default App;
Here, the three elements are grouped together without adding an extra wrapper element to the DOM.
4.2 Explicit React Fragment
You can import Fragment from React and use it to group multiple elements.
import { Fragment } from "react";
function App() {
return (
<Fragment>
<h1>Welcome</h1>
<p>Learn React step by step.</p>
</Fragment>
);
}
export default App;
4.3 When Should You Use Fragments?
- When a component needs to return multiple sibling elements.
- When you do not want unnecessary wrapper elements in the DOM.
- When grouping table rows or other elements with specific parent requirements.
- When keeping the rendered HTML structure simple is important.
Important: The shorthand Fragment syntax cannot accept a key prop. When rendering a group of elements inside a list, use the explicit Fragment syntax with a stable key.
5. Rendering Multiple Elements Using Arrays
React can render arrays containing renderable values, including JSX elements. This can be useful when you prepare a group of elements in a variable and return them from a component.
Example:
function App() {
const elements = [
<h1 key="heading">Welcome to React</h1>,
<p key="description">Learn React concepts.</p>,
<button key="button">Get Started</button>
];
return (
<div>
{elements}
</div>
);
}
export default App;
In this example, the array contains three JSX elements, which are rendered inside the parent div. Each element has a distinct key.
Note: When an array represents a collection of similar items, generating the elements from data using map() is usually more maintainable than manually creating an array of JSX elements.
6. Rendering Multiple Elements Using the map() Method
The JavaScript map() method is one of the most common ways to render multiple similar elements in React. It transforms each item in an array into a JSX element.
Syntax:
array.map((item) => (
<element key={item.id}>{item.name}</element>
))
Example:
function App() {
const courses = [
{ id: 1, name: "React JS" },
{ id: 2, name: "JavaScript" },
{ id: 3, name: "HTML and CSS" }
];
return (
<div>
<h1>Available Courses</h1>
<ul>
{courses.map((course) => (
<li key={course.id}>{course.name}</li>
))}
</ul>
</div>
);
}
export default App;
Explanation:
courses contains an array of course objects.
map() processes each course.
- Each course becomes an
li element.
key={course.id} helps React identify each item.
This technique is useful for course lists, product catalogs, menus, employee directories, and other data-driven interfaces.
7. Understanding Keys When Rendering Multiple Elements
A key is a special React attribute used to identify elements among their siblings in a rendered collection. Keys help React determine which items have been added, removed, or reordered.
Example:
function StudentList() {
const students = [
{ id: 101, name: "Aarav" },
{ id: 102, name: "Priya" },
{ id: 103, name: "Rohan" }
];
return (
<ul>
{students.map((student) => (
<li key={student.id}>{student.name}</li>
))}
</ul>
);
}
Each student has a unique ID, so it can be used as a key.
Best Practices for Keys
- Use a stable, unique ID from the data whenever possible.
- Keys should be unique among sibling elements.
- Avoid generating keys randomly during rendering.
- Avoid using array indexes as keys when items may be inserted, deleted, or reordered.
- Remember that
key is for React and is not passed to the component as an ordinary prop.
Incorrect:
{students.map((student) => (
<li>{student.name}</li>
))}
Correct:
{students.map((student) => (
<li key={student.id}>{student.name}</li>
))}
8. Rendering Multiple Elements Using Reusable Components
Instead of writing the same JSX structure repeatedly, you can create a reusable component and render it multiple times.
Example:
function CourseCard({ name, duration }) {
return (
<div className="course-card">
<h2>{name}</h2>
<p>Duration: {duration}</p>
</div>
);
}
function App() {
return (
<main>
<h1>Our Courses</h1>
<CourseCard name="React JS" duration="8 Weeks" />
<CourseCard name="JavaScript" duration="6 Weeks" />
<CourseCard name="HTML and CSS" duration="4 Weeks" />
</main>
);
}
export default App;
Here, the CourseCard component is reused three times with different props. Each instance displays different course information.
Advantages:
- Reduces duplicated code.
- Makes the application easier to maintain.
- Improves consistency across repeated UI elements.
- Allows each component to receive different data through props.
9. Rendering Multiple Components with a Fragment
You can use Fragments to group several component instances without adding an extra DOM wrapper.
function Header() {
return <h1>My Learning Portal</h1>;
}
function Content() {
return <p>Explore our technology courses.</p>;
}
function Footer() {
return <footer>Copyright 2026</footer>;
}
function App() {
return (
<>
<Header />
<Content />
<Footer />
</>
);
}
export default App;
The App component renders the Header, Content, and Footer components together using a Fragment.
10. Rendering Multiple Elements with Conditional Rendering
You can combine multiple elements with conditional expressions to display content only when a condition is satisfied.
Example:
function App() {
const isLoggedIn = true;
return (
<div>
{isLoggedIn ? (
<>
<h1>Welcome Back!</h1>
<p>You are successfully logged in.</p>
<button>Open Dashboard</button>
</>
) : (
<>
<h1>Welcome Guest</h1>
<p>Please sign in to continue.</p>
<button>Login</button>
</>
)}
</div>
);
}
When isLoggedIn is true, the first group of elements is rendered. Otherwise, the second group is rendered.
Fragments are useful here because each condition returns multiple sibling elements without introducing an unnecessary wrapper.
11. Rendering Multiple Elements with filter() and map()
The filter() method selects items that meet a condition, while map() transforms the selected items into JSX elements. These methods are often used together to display only relevant data.
Example:
function App() {
const courses = [
{ id: 1, name: "React JS", isAvailable: true },
{ id: 2, name: "Python", isAvailable: false },
{ id: 3, name: "JavaScript", isAvailable: true }
];
const availableCourses = courses.filter(
(course) => course.isAvailable
);
return (
<div>
<h1>Available Courses</h1>
<ul>
{availableCourses.map((course) => (
<li key={course.id}>{course.name}</li>
))}
</ul>
</div>
);
}
Only React JS and JavaScript appear in the rendered list because Python is marked as unavailable.
12. Rendering Multiple Table Elements
HTML tables have specific structural requirements. React Fragments can group table cells or rows without introducing an invalid wrapper element.
Example:
function TableRow({ student }) {
return (
<tr>
<td>{student.id}</td>
<td>{student.name}</td>
<td>{student.course}</td>
</tr>
);
}
function App() {
const students = [
{ id: 1, name: "Aarav", course: "React JS" },
{ id: 2, name: "Priya", course: "JavaScript" }
];
return (
<table border="1" cellPadding="8">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Course</th>
</tr>
</thead>
<tbody>
{students.map((student) => (
<TableRow key={student.id} student={student} />
))}
</tbody>
</table>
);
}
Each student is rendered as a table row, and the key is attached to the component returned directly by map().
13. Rendering Multiple Elements Inside a Component
A component can organize related UI into multiple child elements. Smaller components make the structure easier to understand.
function Profile() {
return (
<section className="profile">
<img src="/images/profile.png" alt="User profile" />
<div>
<h2>Ananya Sharma</h2>
<p>Frontend Developer</p>
<button>View Profile</button>
</div>
</section>
);
}
function App() {
return (
<main>
<h1>Team Members</h1>
<Profile />
</main>
);
}
The Profile component contains several elements, and the App component renders it as part of a larger interface.
14. Common Mistakes When Rendering Multiple Elements
| Mistake |
Correct Approach |
Explanation |
| Returning multiple sibling elements without grouping. |
Wrap them in a parent element or Fragment. |
A component return expression needs one root JSX expression. |
| Adding unnecessary wrapper elements. |
Use a Fragment when no DOM wrapper is needed. |
Fragments group elements without adding a DOM node. |
| Rendering list items without keys. |
Use stable, unique keys. |
Keys help React track items when a list changes. |
| Using random values as keys on every render. |
Use stable IDs from the data. |
Changing keys can cause elements to be recreated unnecessarily. |
| Using the shorthand Fragment in a list where a key is needed. |
Use . |
The shorthand Fragment cannot accept a key prop. |
| Repeating similar JSX for many data items. |
Use a reusable component and map(). |
This reduces duplication and improves maintainability. |
| Forgetting to return JSX from a block-bodied arrow function. |
Use an explicit return or an implicit expression return. |
Without a return, the callback produces undefined. |
| Using an invalid wrapper inside a table. |
Use valid table structure and Fragments where appropriate. |
HTML elements must follow the table's structural rules. |
15. Practical Example: Course Listing Application
This example combines reusable components, arrays, map(), keys, and Fragments to render multiple courses.
function CourseCard({ course }) {
return (
<article className="course-card">
<h2>{course.name}</h2>
<p>Duration: {course.duration}</p>
<p>Level: {course.level}</p>
<button>View Details</button>
</article>
);
}
function App() {
const courses = [
{
id: 1,
name: "React JS",
duration: "8 Weeks",
level: "Beginner"
},
{
id: 2,
name: "JavaScript",
duration: "6 Weeks",
level: "Beginner"
},
{
id: 3,
name: "Advanced React",
duration: "10 Weeks",
level: "Advanced"
}
];
return (
<>
<header>
<h1>Technology Training Courses</h1>
<p>Choose a course to begin learning.</p>
</header>
<main className="course-list">
{courses.map((course) => (
<CourseCard key={course.id} course={course} />
))}
</main>
</>
);
}
export default App;
Concepts covered:
- Multiple elements grouped using a Fragment.
- Reusable course card component.
- Array of course objects.
map() for rendering multiple course cards.
- Stable keys using course IDs.
- Props used to pass course data.
16. Difference Between Parent Elements, Fragments, and Arrays
| Feature |
Parent Element |
React Fragment |
Array of Elements |
| Purpose |
Groups elements in a container. |
Groups elements without a wrapper DOM node. |
Stores or produces multiple renderable elements. |
| Extra DOM wrapper |
Yes, for a DOM parent such as div. |
No. |
Not inherently; the surrounding structure depends on where the array is rendered. |
| Syntax |
... |
<>...> |
[element1, element2] |
| Can contain multiple elements |
Yes. |
Yes. |
Yes. |
| Common use |
Layout and styling. |
Grouping without an extra DOM node. |
Rendering prepared elements or collections. |
| Keys needed |
Not merely because it is a parent. |
Needed when each Fragment is an item in a rendered list. |
List children need appropriate keys when generated as a collection. |
17. Best Practices for Rendering Multiple Elements
- Use semantic parent elements when they improve the structure of the page.
- Use Fragments when you need to group elements without adding an extra DOM node.
- Use reusable components for repeated UI patterns.
- Use
map() to render collections of data.
- Provide stable, unique keys for list items.
- Use the explicit
Fragment component when a Fragment in a list needs a key.
- Keep components small and focused on one responsibility.
- Choose valid HTML structures for tables, lists, and other specialized elements.
- Use clear variable and component names.
- Avoid repeating large blocks of JSX unnecessarily.
- Use conditional rendering to display elements only when needed.
- Test the rendered interface and check the browser console for warnings.
18. Interview Questions and Answers
Q1. What does rendering multiple elements mean in React?
It means displaying multiple JSX elements or components together in the user interface, such as headings, paragraphs, buttons, and cards.
Q2. Why does React require a single root JSX expression in a component return?
The component must return one JSX expression. Multiple sibling elements can be grouped using a parent element or a Fragment.
Q3. What is a React Fragment?
A Fragment groups multiple elements without adding an extra DOM element. It can be written using <>...> or the explicit Fragment component.
Q4. What is the difference between a parent element and a Fragment?
A parent DOM element such as div appears in the rendered DOM, while a Fragment groups its children without introducing an extra DOM node.
Q5. How does map() help render multiple elements?
The map() method transforms each item in an array into a JSX element or component, making it easy to render collections.
Q6. Why are keys important in React lists?
Keys help React identify each sibling item when elements are added, removed, or reordered.
Q7. Can a component return an array of JSX elements?
Yes. React can render arrays of renderable elements. When rendering a collection, provide appropriate keys for the items.
Q8. When should you use reusable components?
Use reusable components when the same UI structure appears multiple times with different data, such as product cards, student profiles, or course cards.
Q9. Can Fragments be used inside map()?
Yes. When each item needs multiple sibling elements, use the explicit Fragment component with a stable key.
Q10. What is the difference between map() and filter()?
map() transforms each item into a new value, often a JSX element. filter() selects only the items that satisfy a condition.
19. Quick Revision Checklist
- Understand how React renders multiple JSX elements.
- Know how to group elements using a parent element.
- Understand Fragment shorthand and explicit Fragment syntax.
- Know when an extra DOM wrapper should be avoided.
- Render arrays of elements correctly.
- Use
map() to render data-driven lists.
- Understand the purpose of stable keys.
- Create reusable components and pass data through props.
- Combine conditional rendering with multiple elements.
- Use
filter() to display selected items.
- Practice rendering course cards, student lists, and tables.
20. Conclusion
Rendering multiple elements is an essential React JS skill. Developers can group elements using parent containers or Fragments, create collections using arrays and map(), and build reusable interfaces with components and props. Stable keys and valid JSX structure help keep the code reliable and maintainable.
Practice these techniques by creating a course listing page, product catalog, student directory, or dashboard. These projects demonstrate how React combines multiple elements into complete user interfaces.
Useful React JS Training Links