DocsGuidesContext API

Context API

How to use the Context API with Electron Router DOM

The Context API with Electron Router DOM is pretty simple to use, but there are some caveats you need to be aware of!

The Provider must be used in the element prop, so you can't use it at the same level of a Route, because React Router DOM requires a Route, otherwise you will get the following error:

Example of right usage

<Route
  path="/"
  element={
    <SomeProvider>
      <SomePage />
    </SomeProvider>
  }
/>

or you can just pass the Router as children of your Provider:

<SomeProvider>
  <Router
    main={
      <Route
        path="/"
        element={<SomePage />}
      />
    }
  />
</SomeProvider>