27 lines
688 B
TypeScript
Raw Normal View History

2019-11-11 10:40:05 +02:00
import React, { useState, useEffect } from 'react';
import { connect } from 'react-redux';
2019-12-07 13:28:52 +02:00
import { RawIntlProvider, IntlShape } from 'react-intl';
import i18n from 'app/services/i18n';
import { RootState } from 'app/reducers';
2016-05-19 22:41:43 +03:00
2019-11-11 10:40:05 +02:00
type Props = {
2019-12-07 13:28:52 +02:00
children: React.ReactNode;
locale: string;
2019-11-11 10:40:05 +02:00
};
2016-05-19 22:41:43 +03:00
2019-11-11 10:40:05 +02:00
function IntlProvider({ children, locale }: Props) {
const [intl, setIntl] = useState<IntlShape>(i18n.getIntl());
2016-05-19 22:41:43 +03:00
useEffect(() => {
(async () => {
setIntl(await i18n.changeLocale(locale));
})();
}, [locale]);
2016-05-19 22:41:43 +03:00
return <RawIntlProvider value={intl}>{children}</RawIntlProvider>;
2019-11-11 10:40:05 +02:00
}
2016-05-19 22:41:43 +03:00
2019-12-07 13:28:52 +02:00
export default connect(({ i18n: i18nState }: RootState) => i18nState)(
IntlProvider,
2019-11-11 10:40:05 +02:00
);