feat: Accept async function for URL prop #336
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #216
Related pull requests: #268
My first approach was to re-run
ShareButton.handleClick
after callingbeforeOnClick
, 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 inbeforeOnClick
. The problem was that afterbeforeOnClick
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 thebeforeOnClick
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 theurl
prop.Here's a quick example implementation:
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