Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda