/ Timeline

An auto-updating timeago component for React Native using moment.js

An auto-updating timeago component for React Native using moment.js

react-native-timeago

An auto-updating timeago component for React Native using moment.js.

Usage

import React, { Component } from 'react';
import TimeAgo from 'react-native-timeago';

// Timestamp can be any valid data type accepted in a Moment.js constructor
// Currently accepts string, number, array, or a Date instance
let timestamp = "2015-06-21T06:24:44.124Z";

class MyComponent extends Component {

  ...

  render() {
    return (
      <TimeAgo time={timestamp} />
    )
  }

  ...
};

If you'd like to hide the string "ago" from the phrase returned, you can use the hideAgo prop:

...
<TimeAgo time={timestamp} hideAgo={true} />
...

All normal Text props are applicable (including style). Use the interval prop to change the update interval in milliseconds (default: 60000).

// This component would update every 20 seconds
<TimeAgo time={timestamp} interval={20000} />

Support local language

To support local language, you need to require locale language file, and call moment.locale() in your app.
For example

let TimeAgo = require('react-native-timeago');

let moment = require('moment'); //load moment module to set local language
require('moment/locale/zh-cn'); //for import moment local language file during the application build
moment.locale('zh-cn');//set moment local language to zh-cn
...

GitHub

Comments