Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Combining useContext Providers

as im creating a reactjs project , i have devided my context into three separate files , therefore i ended up with three context providers , at first i wrapped all the context providers one by one around my components in app.js , but i figures maybe if i combined all the context providers in one component and use this component to wrap my app.js so i created the file with below code

import React from "react";
import CryptoContextProvider from "./crypto-context";
import NewsContextProvider from "./news-context";
import DataContextProvider from "./index-context";

const allContextProviders = (props) => {
  return (
    <>
      <CryptoContextProvider>
        <NewsContextProvider>
          <DataContextProvider>{props.children}</DataContextProvider>
        </NewsContextProvider>
      </CryptoContextProvider>
    </>
  );
};

export default allContextProviders;

then i wrrap my app.js as follows

import allContextProviders from "./store/allContextProviders";

function App() {
  return (
    <allContextProviders>
      <div className="App">
        <Navbar />
        <Routes>
          <Route path="/" element={<Navigate to="/welcome" />} />
          <Route path="/welcome" element={<Home />} />
          <Route path="/marketplace" element={<Marketplace />} />
          <Route path="/tools" element={<ToolsServices />} />

yet when i trie to wrap my app.js with the allContextProviders component i get this following error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Line 12:8:  'allContextProviders' is defined but never used  no-unused-vars

am i doing something wrong here? your feedback is appreciated

>Solution :

In React to tell it that the variable name is Component ( and please evaluate it ), the name of the component should start with a capital letter like AllContextProvider. Please change it’s name so that React knows and it will evaluate it in run time.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading