-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathApp.tsx
More file actions
53 lines (44 loc) · 1.28 KB
/
App.tsx
File metadata and controls
53 lines (44 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { useEffect, useState } from "react";
import { PayPalSDKProvider } from "./context/sdkContext";
import { ErrorBoundary, useErrorBoundary } from "react-error-boundary";
import { getBrowserSafeClientToken } from "./utils";
import SoccerBall from "./sections/SoccerBall";
function ErrorFallback({ error }: { error: Error }) {
const { resetBoundary } = useErrorBoundary();
return (
<div role="alert">
<p>Something went wrong:</p>
<pre style={{ color: "red" }}>{error.message}</pre>
<button
onClick={() => {
resetBoundary();
}}
>
Try again
</button>
</div>
);
}
function App() {
const [clientToken, setClientToken] = useState<string>("");
useEffect(() => {
const getClientToken = async () => {
const clientToken = await getBrowserSafeClientToken();
setClientToken(clientToken);
};
getClientToken();
}, []);
return (
<ErrorBoundary FallbackComponent={ErrorFallback}>
<PayPalSDKProvider
clientToken={clientToken}
components={["paypal-payments", "venmo-payments"]}
pageType="checkout"
>
<h1>React One-Time Payment Recommended Integration</h1>
<SoccerBall />
</PayPalSDKProvider>
</ErrorBoundary>
);
}
export default App;