Cannot fetch the current provider injected by metamask into a constant

Cannot fetch the current provider injected by metamask into a constant

I created a ReactApp.After creation, within my src folder I created my own folder called web3.js. Within that, I extracted the current provider installed by metamask on the chrome browser and tried to store that provider to a constant. Unfortunately, when I run the app, it provides me a type error saying "TypeError: Cannot read property 'currentProvider' of undefined"

I created a ReactApp.After creation, within my src folder I created my own folder called web3.js. Within that, I extracted the current provider installed by metamask on the chrome browser and tried to store that provider to a constant. Unfortunately, when I run the app, it provides me a type error saying "TypeError: Cannot read property 'currentProvider' of undefined"

I have tried googling this error and cannot figure out the solution to fix this

import Web3 from 'web3';

const web3 = new Web3(window.web3.currentProvider);

export default web3;

Expected: When i run the app, it should not show the type error

Actual: When i run the app, type-error displayed

Images: React-code React error when i run the app

reactjs blockchain

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Revolutionary Application of Blockchain Technology

Our Blockchain Online Training will provide you to learn about Blockchain technology aspects with realty. Our Blockchain Course also includes live sessions, live Projects

Five Blockchain Trends for You to Consider this Year

Our Blockchain Online Training will provide you to learn about Blockchain technology aspects with realty. Our Blockchain Course also includes live sessions, live Projects

Blockchain, The Next Level Transaction Medium for Banking and Financial Services

Our Blockchain Online Training will provide you to learn about Blockchain technology aspects with realty. Our Blockchain Course also includes live sessions, live Projects

What Is The Difference Between Blockchain And Bitcoin?

Get hands on experinece on block chain live industry experts with real world example at Block chain online Training. Enroll for free demo

Blockchain and the future of accountancy

Get hands on experinece on block chain live industry experts with real world example at Block chain online Training. Enroll for free demo