Last active
February 24, 2020 05:59
-
-
Save rcoproc/6fbff9375394416e9f0fa4b2b3025008 to your computer and use it in GitHub Desktop.
Exemplo de um componente(com auto refresh) React com parâmetros Rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
import PropTypes from "prop-types" | |
import Timestamp from "react-timestamp" | |
class Article extends React.Component { | |
render () { | |
return ( | |
<React.Fragment> | |
<div className="article-title"> | |
<a href={this.props.path}>{this.props.title}</a> | |
</div> | |
<div className="article-body"> | |
{this.props.description} | |
<div className="article-meta-details"> | |
<small> | |
Created by: {this.props.author}, | |
<Timestamp relative date={this.props.created_at} />, | |
last updated: | |
<Timestamp relative date={this.props.updated_at} /> | |
</small> | |
</div> | |
</div> | |
</React.Fragment> | |
); | |
} | |
componentDidMount() { | |
var self = this; | |
self._timer = setInterval( function() {self.forceUpdate()}, 1000); | |
} | |
componentWillUnmount() { | |
if (this._timer) { | |
cleanInterval(this._timer); | |
this._timer = null; | |
} | |
} | |
} | |
Article.propTypes = { | |
title: PropTypes.string, | |
path: PropTypes.string, | |
description: PropTypes.string, | |
author: PropTypes.string, | |
created_at: PropTypes.string, | |
updated_at: PropTypes.string, | |
}; | |
export default Article |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment