- npm install react-router-dom
import React from "react";
import { Link } from "react-router-dom";
useReducer
and useContext
are two hooks that are provided by React to handle state management in more complex applications. They are often used together to manage global state in a React application.
useReducer
is a hook that allows you to manage state using a reducer function, similar to the way you might use switch
statements to manage state in a traditional setState
approach. The useReducer
hook takes two arguments: a reducer function that takes in the current state and an action object and returns the new state, and an initial state object.
Here's an example:
import React, { useReducer } from 'react';
const initialState = { count: 0 };
function fetchData() {
return new Promise((resolve, reject) => {
// Make an asynchronous network request
fetch("https://api.example.com/data")
const originalObj = { a: 1, b: { c: 2 } };
// Create a deep copy of the object using JSON.stringify() and JSON.parse()
const clonedObj = JSON.parse(JSON.stringify(originalObj));
<h1>
, <h2>
, <h3>
, and <p>
to establish a clear structure.pagespeed.web.dev
that use lighthouse.