statelyai/blog

Statically render tweets

Closed this issue · 0 comments

The twitter JS widget for embedding tweets is not ideal. it doesn't give you any control over the loading state and when tweets are loaded, there is a layout shift.

Tweets can be statically rendered on the server-side using getStaticProps in NextJS + Twitter API.

fetch('https://api.twitter.com/1.1/search/tweets.json?q=${QUERY}', {
    headers: {
        'Authorization': 'Bearer YOUR_TOKEN'
    }
})

https://github.com/twitterdev/Twitter-API-v2-sample-code/blob/main/Tweet-Lookup/get_tweets_with_bearer_token.js
https://github.com/lfades/static-tweet/blob/master/pages/api/tweets.js