Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

137
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda