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

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Why ReactJS is better for Web Application Development?

Web Application Development is the point of contact for a business in today's digital era. It is important to choose the right platform for Web Application Development to build a high end Web

Top Blockchain Application Development Company

Codezeros is a top **[Blockchain solution and service provider](https://www.codezeros.com/ "Blockchain solution and service provider")** company which reinvents business with Blockchain solutions. Our Blockchain development solutions fortify the...

Top 10 Best Blockchain Programming Language for Blockchain Programmer

We aim at equipping you with every necessary knowledge of the best programming languages for blockchain and you'll learn more 10 Best Blockchain Programming Language for Programmer: C++, Java, Python, Ruby, Solidity, Go, JavaScript...