Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade guide implementing RelativeTime behavior #1374

Merged
merged 2 commits into from
Jul 23, 2019

Conversation

StorytellerCZ
Copy link
Contributor

Adding a section on how to implement the old FormattedRelative behavior in v3. As per discussion in:
#1364

Another option I was thinking about was adding an example was:

import React from 'react';
import PropTypes from 'prop-types';
import { selectUnit } from '@formatjs/intl-utils';
import { FormattedRelativeTime } from 'react-intl';

export const FormattedRelative = ({ value, ...props }) => {
  const selectedUnit = selectUnit(new Date(value) || Date.now());
  return <FormattedRelativeTime {...props} value={selectedUnit.value} unit={selectedUnit.unit} />;
};

FormattedRelative.propTypes = {
  value: PropTypes.oneOfType([ PropTypes.date, PropTypes.string ]).isRequired
};

export default FormattedRelative;

Thoughts?

Adding a section on how to implement the old `FormattedRelative` behavior in v3. As per discussion in:
formatjs#1364

Another option I was thinking about was adding an example was:
```js
import React from 'react';
import PropTypes from 'prop-types';
import { selectUnit } from '@formatjs/intl-utils';
import { FormattedRelativeTime } from 'react-intl';

export const FormattedRelative = ({ value, ...props }) => {
  const selectedUnit = selectUnit(new Date(value) || Date.now());
  return <FormattedRelativeTime {...props} value={selectedUnit.value} unit={selectedUnit.unit} />;
};

FormattedRelative.propTypes = {
  value: PropTypes.oneOfType([ PropTypes.date, PropTypes.string ]).isRequired
};

export default FormattedRelative;
```

Thoughts?
@longlho
Copy link
Member

longlho commented Jul 23, 2019

LGTM, can u run format:fix?

@longlho longlho merged commit f8ddcd0 into formatjs:master Jul 23, 2019
@StorytellerCZ StorytellerCZ deleted the patch-1 branch July 24, 2019 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants