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

108
Vistas
I am new to react and I'm not sure how to implement the stripe Elements in my app.js

My App.js looks like this

import { BrowserRouter, Routes, Route } from 'react-router-dom' 
import { Elements } from '@stripe/react-stripe-js'
import { loadStripe } from '@stripe/stripe-js'

function App() {

  const [stripeApiKey, setStripeApiKey] = useState('');

  useEffect(() => {
    store.dispatch(loadUser())

    async function getStripApiKey() {
      const { data } = await axios.get('/api/v1/stripeapi');

      setStripeApiKey(data.stripeApiKey)
    }

    getStripApiKey();

  }, [])

  return (
            <BrowserRouter>
              <Routes>
                {stripeApiKey && 
                   <Elements stripe={loadStripe(stripeApiKey)}>
                      <Route path = "/payment" element={<Payment/>} exact/>
                   </Elements>
              </Routes>
           
          }

The browser returns an error saying that the elements is not a route component but I don't know how else to render it. I read the stripe/react documentation sample but i still cant get it to work.

I keep getting this error in my console

"index.tsx:19 Uncaught (in promise) Error: [Elements] is not a component. All component children of < Routes > must be a < Route > or <React.Fragment>"

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The error is quite clear: within a , all direct children must be routes.

Move the wrap inside element={...}.

try this code it should work.

happy coding !

        <Route path = "/payment" element={ stripeApiKey && 
          <Elements stripe={loadStripe(stripeApiKey)}> <Payment/> </Elements>} exact/>
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