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

111
Views
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 answers
Answer question

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 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!