1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-11 00:52:29 +01:00

30 lines
777 B
TypeScript
Raw Normal View History

/**
* This component initializes the stripe's Elements tag with the API key
*/
import React, { memo, useEffect, useState } from 'react';
import { Elements } from '@stripe/react-stripe-js';
import { loadStripe } from "@stripe/stripe-js";
2020-11-24 16:26:18 +01:00
import SettingAPI from '../api/setting';
import { SettingName } from '../models/setting';
2020-11-24 16:26:18 +01:00
const stripePublicKey = SettingAPI.get(SettingName.StripePublicKey);
export const StripeElements: React.FC = memo(({ children }) => {
const [stripe, setStripe] = useState(undefined);
useEffect(() => {
const key = stripePublicKey.read();
const promise = loadStripe(key.value);
setStripe(promise);
}, [])
return (
<div>
{stripe && <Elements stripe={stripe}>
{children}
</Elements>}
</div>
);
})