Answer the question
In order to leave comments, you need to log in
How to include js date-fns library?
Good afternoon, I'm trying to connect the js date-fns library. I do everything according to official documents, but it displays an error - RangeError: Invalid time value. Please tell me how to fix.
import React from 'react';
import PropTypes from 'prop-types';
import formatDistanceToNow from 'date-fns/formatDistanceToNow';
import ruLocale from 'date-fns/locale/ru';
import './Message.scss';
const Message = ({avatar, user, text, date}) => (
<div className="message">
<div className='message__avatar'>
<img src={avatar} alt={`Avatar ${user.fullname} `}/>
</div>
<div className='message__content'>
<div className='message__bubble'>
<p className='message__text' > {text} </p>
</div>
<span className='message__date'>
{formatDistanceToNow(date, 'ddd/MMM/D/YYYY/hh/m/ss', { addSuffix: true , locale: ruLocale})}
</span>
</div>
</div>
);
Message.defaultProps = {
user: {}
}
Message.propTypes = {
avatar: PropTypes.string,
text: PropTypes.string,
date: PropTypes.string,
user: PropTypes.object
};
export default Message;
import React from 'react';
import { Message } from 'components';
import './Home.scss';
const Home = () => (
<section className='home'>
<Message
avatar='https://sun9-11.userapi.com/c850132/v850132685/15890d/Dqx3pZ4zCw8.jpg?ava=1'
text='Hi!'
date='(Thu Aug 29 2019 11:22:58)'/>
</section>
)
export default Home;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question