React Lists

We can create lists in React in a similar manner as we do in regular JavaScript i.e. by storing the list in an array. In order to traverse a list we will use the map() function.

Keys are used in React to identify which items in the list are changed, updated, or deleted. Keys are used to give an identity to the elements in the lists. It is recommended to use a string as a key that uniquely identifies the items in the list.

Code Snippet:

const arr = [];
const listItems = numbers.map((number) =>
<li key={number.toString()}>
{number}
</li>
);

Javascript




import React from 'react';
import ReactDOM from 'react-dom';
 
const numbers = [1,2,3,4,5];
 
const updatedNums = numbers.map((number)=>{
    return <li>{number}</li>;
});
 
ReactDOM.render(
    <ul>
        {updatedNums}
    </ul>,
    document.getElementById('root')
);


React Cheat Sheet

React is an open-source JavaScript library used to create user interfaces in a declarative and efficient way. It is a component-based front-end library responsible only for the view layer of a Model View Controller (MVC) architecture. React is used to create modular user interfaces and promotes the development of reusable UI components that display dynamic data.

React Cheat Sheet provides you with a simple, quick reference to commonly used React methods. All the important components and methods are provided in this single page

Table of Content

  • React Elements
  • ReactJS Import and Export
  • React Components
  • Lifecycle of Components
  • Conditional Rendering
  • React Lists
  • React DOM Events
  • React Hooks
  • PropTypes

Boilerplate: Follow the below steps to create a boilerplate

Step 1: Create the application using the command

npx create-react-app <<Project_Name>>

Step 2: Navigate to the folder using the command

cd <<Project_Name>>

Step 3: Open the App.js file and write the below code

Javascript




// App.js
 
import React from 'react';
import './App.css';
export default function App() {
    return (
        <div >
            Hello Geeks
            Lets start learning React
        </div>
    )
}


Similar Reads

JSX

...

React Elements

JSX stands for JavaScript XML. JSX is basically a syntax extension of JavaScript. It helps us to write HTML in JavaScript and forms the basis of React Development. Using JSX is not compulsory but it is highly recommended for programming in React as it makes the development process easier as the code becomes easy to write and read....

ReactJS Import and Export

React elements are different from DOM elements as React elements are simple JavaScript objects and are efficient to create. React elements are the building blocks of any React app and should not be confused with React components....

React Components

In ReactJS we use importing and exporting to import already created modules and export our own components and modules rescpectively...

Lifecycle of Components

A Component is one of the core building blocks of React. Components in React basically return a piece of JSX code that tells what should be rendered on the screen....

Conditional Rendering

...

React Lists

...

React DOM Events

The lifecycle methods in ReactJS are used to control the components at different stages from initialization till unmounting....

React Hooks

...

PropTypes

In React, conditional rendering is used to render components based on some conditions. If the condition is satisfied then only the component will be rendered. This helps in encapsulation as the user is allowed to see only the desired component and nothing else....

Error Boundaries

...