Skip to content

Commit 084f6d5

Browse files
committed
feat(ShareButton): Accept async function as the url prop
1 parent 61b74ad commit 084f6d5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/ShareButton.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ interface CustomProps<LinkOptions> {
8181
openShareDialogOnClick?: boolean;
8282
opts: LinkOptions;
8383
/**
84-
* URL of the shared page
84+
* URL of the shared page, can be an async function that resolves a URL
8585
*/
86-
url: string;
86+
url: string | (() => Promise<string>);
8787
style?: React.CSSProperties;
8888
windowWidth?: number;
8989
windowHeight?: number;
@@ -93,6 +93,7 @@ interface CustomProps<LinkOptions> {
9393
* `onClick`. If you do not return promise, `onClick` is called immediately.
9494
*/
9595
beforeOnClick?: () => Promise<void> | void;
96+
9697
/**
9798
* Takes a function to be called after closing share dialog.
9899
*/
@@ -138,11 +139,16 @@ export default class ShareButton<LinkOptions> extends Component<Props<LinkOption
138139
disabled,
139140
networkLink,
140141
onClick,
141-
url,
142142
openShareDialogOnClick,
143143
opts,
144144
} = this.props;
145145

146+
let url = this.props.url;
147+
148+
if (typeof url == 'function') {
149+
url = await url();
150+
}
151+
146152
const link = networkLink(url, opts);
147153

148154
if (disabled) {

0 commit comments

Comments
 (0)