Master raj
7 min readMay 13, 2023

Preparing for React: What You Need to Know!!!

🥇 So Let’s start.

Map and Filter are two important array methods that are commonly used in React development. They allow developers to efficiently transform data and manipulate the rendering of components. Here’s a brief explanation of how they work in React:

Map:
The map method allows developers to iterate over an array and create a new array with modified values based on each item in the original array. In React, this is often used to transform data before rendering it as JSX. For example:

const numbers = [1, 2, 3, 4, 5];

const doubledNumbers = numbers.map((number) => number * 2);

console.log(doubledNumbers); // [2, 4, 6, 8, 10]

Filter:
The filter method allows developers to iterate over an array and create a new array with only the items that pass a given condition. In React, this is often used to selectively render components based on certain data criteria. For example:

slice():
The slice() method allows developers to create a new array from a portion of an existing array without modifying the original array. This method can be useful in React when working with paginated data or when only needing to render a specific subset of data. For example:

const numbers = [1, 2, 3, 4, 5];

const slicedNumbers = numbers.slice(1, 4);

console.log(slicedNumbers); // [2, 3, 4]

In this example, slice(1, 4) creates a new array that includes elements from the original array numbers starting at index 1 and ending at index 4 (not inclusive).

splice():
The splice() method allows developers to modify an array by removing or replacing existing elements or adding new elements to the array. This method can be useful in React when updating the state of a component with new data or modifying a specific portion of an array. For example:

const fruits = ["apple", "banana", "orange", "pear"];

// remove 2 elements starting at index 1 and replace with "grape"
fruits.splice(1, 2, "grape");

console.log(fruits); // ["apple", "grape", "pear"]

In this example, splice(1, 2, "grape") removes two elements from the fruits array starting at index 1 and replaces them with the string "grape".

This is Self Understanding …. 🫢🚧

Again Self Explanatory 🎖️🎉🛣️

Destructuring is a feature introduced in ES6 (ECMAScript 2015) that allows developers to extract values from arrays or objects and assign them to variables in a more concise way. This feature is commonly used in React development to extract and use props and state data in functional components.

Destructuring Arrays:
To destructure an array, we use square brackets [] on the left-hand side of an assignment and list the variables we want to extract in the same order as the values in the array. For example:

const numbers = [1, 2, 3];

const [first, second, third] = numbers;

console.log(first); // 1
console.log(second); // 2
console.log(third); // 3

In this example, const [first, second, third] = numbers extracts the values 1, 2, and 3 from the numbers array and assigns them to the variables first, second, and third, respectively.

Destructuring Objects:
To destructure an object, we use curly braces {} on the left-hand side of an assignment and list the variable names we want to extract, matching the keys in the object. For example:

const person = {
name: "John",
age: 30,
location: "New York",
};

const { name, age, location } = person;

console.log(name); // "John"
console.log(age); // 30
console.log(location); // "New York"

In this example, const { name, age, location } = person extracts the values associated with the keys name, age, and location from the person object and assigns them to the variables name, age, and location, respectively.

In React, destructuring is commonly used to extract and use props and state data in functional components. For example:

function Person({ name, age, location }) {
return (
<div>
<h2>{name}</h2>
<p>{age}</p>
<p>{location}</p>
</div>
);
}

In this example, the Person component destructures the props object to extract the name, age, and location values and uses them directly in the JSX markup.

Most Most Most Important .👿🧐

Rest and spread operators are two features introduced in ES6 (ECMAScript 2015) that are commonly used in React development to manipulate arrays and objects in a more concise and flexible way.

Spread Operator:
The 'spread operator' ... is used to spread the elements of an array or the properties of an object into a new array or object. In React, the spread operator can be useful for combining multiple arrays or objects into a single one or for passing props to child components. For example:

In this example, ...numbers1 and ...numbers2 spread the elements of the two arrays into a new array combinedNumbers.

In this example, { ...person, location: "New York" } spreads the properties of the person object into a new object newPerson and adds a new property location.

Rest Operator:
The rest operator ... is used to represent an indefinite number of arguments as an array. In React, the rest operator can be useful for passing an unknown number of props to a component or for destructuring an array into the first and remaining elements. For example:

In this example, the List component uses the rest operator {...items} to receive an unknown number of items as props and maps over them to render a list.

const numbers = [1, 2, 3, 4, 5];

const [first, ...rest] = numbers;

console.log(first); // 1
console.log(rest); // [2, 3, 4, 5]

In this example, [first, ...rest] = numbers destructures the numbers array into the first element first and the remaining elements rest.

This is Most Imp 👿 Try to Learn It implement it

Promises are a way of handling asynchronous operations in JavaScript, and they are widely used in React applications to manage data fetching and API calls. In short, a Promise is an object that represents a value that may not be available yet but will be resolved at some point in the future. Once the Promise is resolved, it can either return a value or throw an error.

In React, Promises are commonly used with the fetch API to fetch data from an external API. Here's an example of how Promises can be used in a React component:

import React, { useState, useEffect } from "react";

function App() {
const [data, setData] = useState(null);

useEffect(() => {
fetch("https://jsonplaceholder.typicode.com/todos/1")
.then((response) => response.json())
.then((data) => setData(data))
.catch((error) => console.log(error));
}, []);

return (
<div>
{data ? (
<div>
<h2>{data.title}</h2>
<p>{data.completed ? "Completed" : "Not Completed"}</p>
</div>
) : (
<p>Loading...</p>
)}
</div>
);
}

export default App;

In this example, the useEffect hook is used to fetch data from the JSONPlaceholder API using the fetch method. The fetch method returns a Promise, which is then resolved with the .then() method and the response is parsed as JSON using the .json() method. If the Promise is rejected, the error is caught with the .catch() method.

Once the Promise is resolved and the data is available, it is stored in the component's state using the setData method. The state is then used to render the component's content conditionally, based on whether the data has been fetched or not.

So I hope You have Gained Enough Knowledge to start with React Now if you liked the content , don’t forget to 👏 Follow for more updates

If you enjoyed reading this blog, please share it with your friends and make sure to subscribe to our YouTube channel for more exciting content. Help us spread the word about our expertise in MERN stack development, cloud computing, React Native, and Next.js, and stay tuned for more informative articles to come. Together, we can take the tech world by storm!

In the Mern Stack Projects section you can find tutorials, tips, cheat sheets, and other projects. Our talks also focus on React Frameworks like NextJs,AWS Cloud So join us today to keep up with the latest technology🩷
📠 🏅:- Mern Stack Projects
🎦 🥇:- Jara diary - YouTube 🚦
🎦 🥈 :- Errormania - YouTube 🚦
On GITHUB :- raj-28 (Raj) (github.com)
💌 Do Subscribe To Our Mailing List To stay Updated With All New Blogs 👍
…………🚦…🛣… ……………🚧🛑………………..▶……………….️
Use Emojis From Here In Case You Need Any….🚦🛣️🥇🥈🥉🏅🎖️🎦👍

medium.com
Axios Network Error when making HTTP request [Solved] |
# Axios Network Error when making HTTP request [Solved]medium.com

Master raj

Certified MERN Stack Developer from Infosys, now sharing expertise on #InCloudByRK. Proficient in MERN Stack, AWS, GCP, Azure DevOps. Let's level up!