Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Youtube VideoPreview component with proper view count formatting
import {getShortNumberString} from '../../services/number/number-format';
const timeAgo = new TimeAgo('en-US');
export class VideoPreview extends React.Component {
render() {
{/* unchanged */}
static getFormattedViewAndTime(video) {
const publicationDate = new Date(video.snippet.publishedAt);
const viewCount = video.statistics ? video.statistics.viewCount : null;
if(viewCount) {
const viewCountShort = getShortNumberString(video.statistics.viewCount);
return `${viewCountShort} views • ${timeAgo.format(publicationDate)}`;
return '';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment