React Tweet Card
IntroductionInstallationBasic setupTweet author optionsAdding imagesDisplaying engagementServer-side renderingPropsStyling

Installation

npm i react-tweet-card
# or
yarn add react-tweet-card

Basic setup

Here's how to set up a tweet card with basic information:

Tweet author options

You can specify that the author of the tweet you're displaying in the card is either verified or protected (private). The verified badge will show next to the user's name for verified users, and the padlock icon for protected users. To add these properties, add isVerified: true or isProtected: true to the author prop. You can also use isGovernment or isBusiness alongside isVerified.

Adding images

You can add images to a tweet by using the tweetImages prop. You have to pass in an array of objects that have a src property with the URL to your images. You can also add an isVideoThumbnail property set to true, which does exactly what you would think. A maximum of 4 images is allowed within a tweet.

Note: The fitInsideContainer prop makes the card fill out its parent container, so when you're dynamically changing the content of your tweet, make sure to allocate enough visual space for the images, and pay attention the aspect ratio of the container.

Displaying engagement

You can use the engagements prop on the component to display the number of replies, retweets and likes a tweet has received. The layout can look a bit overwhelming when both the tweet's details (time and source) and the engagements are displayed, so you can use the showDetails and showEngagement props to control the layout. Both props are set to true by default.

Using emojis

Setting the emojis prop to true will make the component use emoji characters for the engagement visuals instead of the icons used by Twitter.

Server-side rendering

React Tweet Card can only be rendered on the client side as it loads its CSS directly into the DOM. To make it work with SSR, try importing the package dynamically.