---
title: "How To Create Components Dynamically In React 16"
description: "Learn how to dynamically render an array of React components in React 16 using Array.prototype.map, a JSON data source, and unique key props."
url: "https://react.tips/how-to-create-components-dynamically-in-react-16/"
category: "react"
published: "2019-01-06"
updated: "2026-12-01"
react_version: "16"
proficiency: "Beginner"
keywords: ["dynamic React components", "Array.map", "React keys", "JSX", "React 16"]
author: "Artemij Fedosejev"
---

# How To Create Components Dynamically in React 16

**Quick answer:** Store your items in an array and transform them into JSX elements with `items.map(item => <ItemComponent key={item} ... />)` inside `render()`. Always assign a stable, unique `key` prop so React can track each item efficiently.

One of them most common tasks that we need to know how to do with React is to render a list of items _dynamically_ - meaning: we don't know how many items we're going to render at any given time. Zero or one hundred - it shouldn't matter.

Let's learn how to do it with a help of an intuitive example.

## Demo Application Overview

In this tutorial, we're going to build this application:

![React 16 application dynamically rendering five circular images from an array](./images/app.png)

You can find the full source code in [this GitHub repository](https://github.com/fedosejev/how-to-create-components-dynamically-in-react-16).

Our application is going to render 5 images _dynamically_. There is a catch: our application will work equally well for 50 or any other number of images. Let's see how.

Our application will be made of 2 React components:

1. `App`
2. `Image`

The `App` component is a root component - it encapsulates our entire React application. `Image` component on the other hand renders a single image element.

## Creating the `Image` Child Component

Let's create the `Image` component first:

```jsx
import React from "react";

const Image = ({ source }) => (
  <img src={`./images/${source}`} alt="Example" className="w-25 m-2" />
);

export default Image;
```

*Code snippet 1. Image.js*

As you can see our functional `Image` component renders:

```jsx
<img src={`./images/${source}`} alt="Example" className="w-25 m-2" />
```

*Code snippet 2. Image.js*

`img` DOM element will be rendered when you create an instance of `Image` React component.

We get an image source from the parent React component as a `source` property:

```jsx
src={`./images/${source}`}
```

*Code snippet 3. Image.js*

## Rendering Dynamic `Image` Components in `App`

Now that we have a way to render more than one image - how can we render more than one?

That's a job for our `App` component. Let's create it:

```jsx
import React from "react";
import Image from "./Image";

const IMAGES = [
  "IMG_5774.jpg",
  "IMG_6305.jpg",
  "IMG_6701.jpg",
  "IMG_6732.jpg",
  "IMG_6795.jpg"
];

const App = () => (
  <div className="container">
    <div className="row mt-2 mb-2">
      <div className="col-sm-12 text-center">

        {IMAGES.map(image => (
          <Image source={image} key={image} />
        ))}

      </div>
    </div>
  </div>
);

export default App;
```

*Code snippet 4. App.js*

First we declare `IMAGES` array with five image filenames:

```javascript
const IMAGES = [
  "IMG_5774.jpg",
  "IMG_6305.jpg",
  "IMG_6701.jpg",
  "IMG_6732.jpg",
  "IMG_6795.jpg"
];
```

*Code snippet 5. App.js*

Then we declara our `App` component that renders some layout elements with [Bootstrap](https://getbootstrap.com/) class names and then iterates over `IMAGES` array creating new `Image` component instance for each image:

```jsx
{IMAGES.map(image => (
  <Image source={image} key={image} />
))}
```

*Code snippet 6. App.js*

The `Image` component gets two props: the `source` and the `key` props. Remember that our `Image` component needs to know what image file it should render and `source` property tells it exactly that. But what about that `key` property - we don't use it in our `Image` component - why are we passing it then?

The `key` property is [used by React to uniquely identify](https://reactjs.org/docs/lists-and-keys.html) our `Image` component instances.

Think about it this way: React needs a way to distinguish between multiple instances of a child component (our `Image` component is a child component of `App` component) when they're created _dynamically_.

Naturally, the value for `key` property must be unique. It's up to us where this value is coming from. In this example, all file names are unique, so we're using them as unique keys for dynamic children.

## Let's review

Here is what's happening: in our `App` component React calls `render` function that iterates over `IMAGES` array and creates a new `Image` component instance for each `image` in the `IMAGES` array.

If we later decide to update `IMAGES` array and add another 10 image - our React application will work without any changes. That's the power of dynamically generating child components in React.

And that's how you create components dynamically in React 16.

Thank you for your attention!

Please take a look at [the complete source code on GitHub](https://github.com/fedosejev/how-to-create-components-dynamically-in-react-16) and [the live version](https://fedosejev.github.io/how-to-create-components-dynamically-in-react-16/) of our app.

I hope you've enjoyed this tutorial and I would love to hear your feedback in the comments. You can get in touch with me via [Twitter](https://twitter.com/artemy) and [email](mailto:artemij@fedosejev.com).

[Artemij Fedosejev](https://artemij.com)
