3.2.1 β’ Published 1 year ago
snaptrade-react v3.2.1
π Table of Contents
- π Getting Started
- βοΈ Configuration
- π Using the useWindowMessage Hook
- π¨πΌββοΈ License & copyrights
π Getting Started
npm install snaptrade-react
import { useState } from 'react';
import { SnapTradeReact } from 'snaptrade-react';
const ConnectBrokerage = () => {
const [open, setOpen] = useState(false);
const [redirectLink, setRedirectLink] = useState(null);
const connectionProcess = () => {
// call "https://api.snaptrade.com/api/v1/snapTrade/login" to generate a redirect link
const link = getRedirectURI();
// update the state with the generated link
setRedirectLink(link);
// update the "open" state to show the modal
setOpen(true);
};
return (
<div>
{/* your Connect button */}
<button onClick={connectionProcess}>Connect</button>
<SnapTradeReact
loginLink={redirectLink}
isOpen={open}
close={() => setOpen(false)}
/>
</div>
);
};
export default ConnectBrokerage;
βοΈ Configuration
SnapTradeReact
requires the following props:
*: optional
Prop | Type | Default value | Description |
---|---|---|---|
loginLink | string | undefined | The generated redirect link. (retrieve by calling https://api.snaptrade.com/api/v1/snapTrade/login ) |
isOpen | boolean | undefined | Determines to show/hide the modal. |
close | Function | undefined | A function to be called when user clicks out of the modal or click the X button. |
onSuccess* | Function | undefined | A callback function that is executed upon successful connection to a brokerage. This function returns the authorization ID associated with the new connection. |
onError* | Function | undefined | A callback function that is triggered when a user encounters an error while attempting to connect to a brokerage. This function returns an object containing both an error code, status code and a detailed description of the error. |
onExit* | Function | undefined | A callback function that is triggered when a user closes the modal or exits the second tab (opened for making an oAuth connection) without successfully connecting to a brokerage. |
contentLabel* | string | Connect Account via SnapTrade | Indicating how the content container should be announced to screenreaders. |
style* | overlay: { backgroundColor: string, zIndex: number} | overlay: { backgroundColor: 'rgba(255, 255, 255, 0.75)', zIndex: 1} | Change styling for the overlay. |
π Using the useWindowMessage Hook
The useWindowMessage
hook can be used to listen for window messages and handle success, error, exit, and close modal events. Hereβs how to use it:
import { useEffect } from 'react';
import { useWindowMessage } from 'snaptrade-react/hooks/useWindowMessage';
const MyComponent = () => {
const onSuccess = (data) => {
console.log('Success:', data);
};
const onError = (data) => {
console.error('Error:', data);
};
const onExit = () => {
console.log('Exit');
};
const close = () => {
console.log('Close');
};
useWindowMessage({
handleSuccess: onSuccess,
handleError: onError,
handleExit: onExit,
close: close,
});
return <div>My Component</div>;
};
export default MyComponent;
This hook handles the SUCCESS, ERROR, CLOSED, and CLOSE_MODAL events and triggers the corresponding callbacks.
π¨πΌββοΈ License & copyrights
Licensed under Apache License 2.0.
3.2.1
1 year ago
3.2.0
1 year ago
3.1.1
1 year ago
3.1.0
1 year ago
1.7.3
2 years ago
1.7.2
2 years ago
1.7.1
2 years ago
3.0.0
2 years ago
1.7.0
2 years ago
1.6.4
2 years ago
1.6.3
2 years ago
1.6.2
2 years ago
1.6.7-beta.0
2 years ago
1.6.9
2 years ago
1.6.8
2 years ago
1.6.7
2 years ago
1.6.9-test.0
2 years ago
1.6.5
2 years ago
1.6.1
2 years ago
1.5.2
2 years ago
1.6.0
2 years ago
1.5.1
2 years ago
1.5.0
2 years ago
1.4.1
3 years ago
1.2.0
3 years ago
1.1.0
3 years ago
1.0.0-experimental
3 years ago
1.3.2
3 years ago
1.4.0
3 years ago
1.3.1
3 years ago
1.3.0
3 years ago
1.0.0-experimental-240822
3 years ago
1.0.0
3 years ago