saurabhnemade / react-twitter-embed

Simplest way to add twitter widgets to your react project.
https://saurabhnemade.github.io/react-twitter-embed/
368 stars 66 forks source link

onloading placeholder component #36

Closed pantchox closed 5 years ago

pantchox commented 5 years ago

Hello,

Wanted to know if there is an option to pass a component as a prop to show until the tweet is loaded.

thanks.

dandv commented 5 years ago

:+1: to this request. When loading multiple tweets at once if you know their text (e.g. have it from an API), it helps to show the text while the tweets load.

pantchox commented 5 years ago

Hi,

I don't understand you comment as a solution can you please clarify with an example. My solution was a "hack"

import {TwitterTweetEmbed} from 'react-twitter-embed';
...
const {error, loading} = this.state;
...
{loading && <YourLoaderHere />
{!error && <TwitterTweetEmbed
    tweetId={tweetId}
    options={{width: 'auto'}}
    onLoaded={(el) =>
        (el ? this.setState({loading: false}) : this.setState({loading: false, error: true}))} />}

I was checking if the element was valid on the DOM if not I assume error happened, I checked this with giving invalid tweetId or creating a tweet and then intentional delete it to check.

dandv commented 5 years ago

@pantchox: please reopen the issue, as there is no solution. We also use a wrapper component on our site, and it would be nice to have the placeholder functionality built into this library.

The competing library react-tweet-embed has implemented this feature already but I can't get it to work.

saurabhnemade commented 5 years ago

@dandv @pantchox Yes. Its definitely a must have feature. We should definitely have it. So to address that I am opening a PR shortly.