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

276
Views
i use element insted of route becouse i use stripe for online payment

Error: [Elements] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>

import { Elements } from "@stripe/react-stripe-js";
import { loadStripe } from "@stripe/stripe-js";

<Elements stripe={loadStripe(stripApikey)}>
  <Route
    path="/process/payment"
    element={
      <ProtectedR>
        <Payments />
      </ProtectedR>
    }
  />
</Elements>

I wrapped all in route like that <Route path="/process/payment" element={<ProtectedR ><Elements stripe={loadStripe(stripApikey)}><Payments /></Elements></ProtectedR>} /> but after its gives error in my payment file × Error: Could not find Elements context; You need to wrap the part of your app

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

0

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

Move the <Elements> wrap inside element={...}.

<Route
  path="/process/payment"
  element={
    <ProtectedR>
      <Elements stripe={loadStripe(stripApikey)}>
        <Payments />
      </Elements>
    </ProtectedR>
  }
/>
about 4 years ago · Juan Pablo Isaza Report

0

React Router, version 6

  • Since [Elements] is not a <Route> component, it cannot be wrapped inside <Route>. That means Elements should be placed outside <Route>.

  • All component children of <Routes> must be a <Route> or
    <React.Fragment>. Therefore, if there is a <Route> component, it must be wrapped around <Routes>.

The above statements result to the following syntax (in your case, there is a Protected Route):

<Elements stripe={loadStripe(stripeApiKey)}>
    <Routes>
        <Route exact path="/process/payment" element={<ProtectedRoute />}>
            <Route exact path="/process/payment" element={<Payments />} />
        </Route>
     </Routes>
</Elements>
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!