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

feat: Accept async function for URL prop #336

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Kashuab
Copy link

@Kashuab Kashuab commented Jul 20, 2020

Closes #216
Related pull requests: #268

My first approach was to re-run ShareButton.handleClick after calling beforeOnClick, but I felt the solution was unreliable and messy. My actual use-case requires me to upload an image to a third party service (which returns a URL to the image), which I was doing in beforeOnClick. The problem was that after beforeOnClick was called, any props that got updated were not used.

Instead of relying on changing props by calling setState in the parent component that contains the beforeOnClick prop in order to dynamically specify a URL (which is very complicated,) I think it's a lot simpler to accept an async function instead for the url prop.

Here's a quick example implementation:

import { FacebookShareButton, FacebookIcon } from 'react-share';

const DynamicURLShare = () => {
  const getUrl = async () => {
    // ... make a fetch call, etc.

    return 'some URL';
  };

  return (
    <FacebookShareButton url={getUrl} quote="Testing 123">
      <FacebookIcon />
    </FacebookShareButton>
  );
};

This is my first ever open-source contribution, so let me know if there's anything I'm missing!

If you need to use this feature before it's merged, I've published a package in the interim: @kashuab/react-share

@Kashuab Kashuab changed the title feat: Re-run handleClick after beforeOnClick is called feat: Handle prop changes from beforeOnClick Jul 22, 2020
@Kashuab Kashuab changed the title feat: Handle prop changes from beforeOnClick feat: Accept async function for URL prop Jul 23, 2020
@Kashuab Kashuab marked this pull request as ready for review July 23, 2020 18:04
@Kashuab
Copy link
Author

Kashuab commented Aug 8, 2022

Made a commit on my fork to resolve the edits I made to package.json before publishing the package to be used until this is merged 👍

@jonknyc
Copy link

jonknyc commented Nov 3, 2022

would love to get this merged in - I need the same feature

@wstuckey
Copy link

any chance of this getting merged in?

@Hubackova
Copy link

I also need this feature, is there a chance to merge in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create URL before share
5 participants