Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
Separate ApolloProvider component render with ReactDOM giving error

I have the following ApolloProvider setup inside index.js in my React application. It's working fine connecting to the Apollo server.

import { React } from 'react';
import * as ReactDOM from 'react-dom/client';
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';
import App from './App';
import { createHttpLink } from 'apollo-link-http';

const httpLink = createHttpLink({
    uri: 'http://localhost:5002'
})

const client = new ApolloClient({
    link: httpLink,
    cache: new InMemoryCache()
})

export default (
    <ApolloProvider client = { client } >
        <App/>
    </ApolloProvider>
)
  
 const root = ReactDOM.createRoot(document.getElementById('root'));
  
  root.render(
    <ApolloProvider client={client}>
      <App />
    </ApolloProvider>,
  );

Now I need to decouple this I try to introduce a new Component called ApolloProvider inside a ApolloProvider.js:

import React from "react";
import App from "./App";
import { createHttpLink } from 'apollo-link-http';
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';

const httpLink = createHttpLink({
    uri: 'http://localhost:5002'
})

const client = new ApolloClient({
    link: httpLink,
    cache: new InMemoryCache()
})

export default (
    <ApolloProvider client = { client } >
        <App/>
    </ApolloProvider>
)

Then I try to render like the following in index.js:

import ReactDOM from 'react-dom';
import ApolloProvider from './ApolloProvider';

ReactDOM.render(ApolloProvider, document.getElementById('root'));

But here I'm getting the following error

ReactDOM.render is no longer supported in React 18. Use createRoot instead.

enter image description here

I tried few syntaxes with createRoot still no clear path for this.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You seem to be using the syntax used to render the app for React v17 while you have installed React v18. You have two choices to make that warning go away:

  1. Change index.js so that you use the setup for React v18:
import React from "react";
import ReactDOM from "react-dom/client";
import ApolloProvider from './ApolloProvider';

const root = ReactDOM.createRoot(document.getElementById("root"));
// if you are rendering App as a normal component use this line:
// root.render(<React.StrictMode><App/></React.StrictMode>);
// the below line is specific to how the question is made:
root.render(<React.StrictMode>{ApolloProvider}</React.StrictMode>)

  1. Keep everything as it's but downgrade your React version. For that replace the three lines below with what you have in package.json, then run npm i and npm start :
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "5.0.0",
about 4 years ago · Juan Pablo Isaza Report

0

I was able to find a solution by observing the following documentation https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html#updates-to-client-rendering-apis

import App from './App';
import { createRoot } from 'react-dom/client';
import ApolloProvider from './ApolloProvider';

const container = (ApolloProvider, document.getElementById('root'));
const root = createRoot(container);
root.render(<App/>);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!