Skip to content

A react-native and react (via react-native-web) component to display time "as of X ago"

Notifications You must be signed in to change notification settings

DSchau/react-native-timeago

Repository files navigation

react-native-timeago

Travis npm package Coveralls

A component to display time formatted in "calendar time," or "time ago." For instance, given a time 10 minutes previous to now, the component will render "10 minutes ago." Additionally, the component updates this calendar time with an interval.

The component works seamlessly with both react-native and the web (via react-native-web)

Install

yarn add @dschau/react-native-timeago

Usage

import React from 'react-native';
import {
  View
} from 'react-native';

import TimeAgo from '@dschau/react-native-timeago';

export default function TimeAgoContainer() {
  return (
    <View>
      <TimeAgo time={new Date('01/01/1970')} />
    </View>
  );
}

Props

time

Use to set the "start" date for comparison to now. Accepts number, string, or Date.

prefix

Sets the prefix to display before to the calendar time. For instance, prefix="as of" will render as of X ago.

Default is false.

suffix

Sets the suffix to display after the calendar time. For instance, suffix="some time ago" will render 10 minutes some time ago.

Default is ago, set to false to disable.

interval

Set the interval to customize when now is re-set.

Default is 60000 (1 minute in MS)

className

Set to add a className to the internal Text element

Default is ''

style

Customize the internal style of the internal Text element

About

A react-native and react (via react-native-web) component to display time "as of X ago"

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published