Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md #17

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@ to trigger the Dropin.
> story](https://gocardless.github.io/react-dropin/?path=/story/dropin-gocardlessdropinbutton--base)

```typescript
import React, { useCallback, useState } from "react";
import React, { FC, useState, useEffect } from "react";
import {
useGoCardlessDropin,
GoCardlessDropinOptions,
GoCardlessDropinOnSuccess,
}
} from '@gocardless/react-dropin'

// Display a button that opens the Dropin on click, starting a checkout
// flow for the specified Billing Request Flow.
const DropinButton = (options: GoCardlessDropinOptions) => {
const DropinButton: FC<GoCardlessDropinOptions> = (options) => {
const { open } = useGoCardlessDropin({ ...options });

return (
Expand All @@ -53,8 +52,8 @@ const DropinButton = (options: GoCardlessDropinOptions) => {

// Example checkout flow, where we create a Billing Request Flow ID by talking
// with our backend API.
const App: FunctionComponent = () => {
const [flowID, setFlowID] = useState<string | null>(null);
const App: FC = () => {
const [flowID, setFlowID] = useState("");

// Build your backend with an API endpoint that:
//
Expand All @@ -64,7 +63,7 @@ const App: FunctionComponent = () => {
//
// See an example of this at Taking an Instant Bank Payment:
// https://developer.gocardless.com/getting-started/billing-requests/taking-an-instant-bank-payment/
React.useEffect(() => {
useEffect(() => {
async function createFlow() {
// Expecting a JSON body like:
// {
Expand All @@ -80,7 +79,7 @@ const App: FunctionComponent = () => {
}, []);

// Only show the button once we have a Billing Request Flow ID
return token === null ? (
return flowID ? (
<div className="loader"></div>
) : (
<DropinButton billingRequestFlowID={flowID} environment={"live"} />
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type CommonOptions = ClientCallbacks & {
/**
* Environment name, one of live or sandbox.
*/
environment: string;
environment: "live" | "sandbox";
/**
* Domain override if using a custom environment (for internal use only).
*/
Expand Down