UNPKG

react-translate-maker

Version:

React translation module. Internationalize your great project.

43 lines (41 loc) 973 B
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import { useContext, useCallback } from 'react'; import TranslateContext from './TranslateContext'; export default function LocaleSwitch(props) { const { onError, onChange, children } = props; const { translate } = useContext(TranslateContext); const handleChange = useCallback( /*#__PURE__*/ function () { var _ref = _asyncToGenerator(function* (locale) { try { yield translate.setLocale(locale); if (onChange) { onChange(locale); } } catch (e) { if (onError) { onError(e); } } }); return function (_x) { return _ref.apply(this, arguments); }; }(), []); return children({ locale: translate.getLocale(), changeLocale: handleChange }); } LocaleSwitch.defaultProps = { onError: undefined, onChange: undefined }; //# sourceMappingURL=LocaleSwitch.js.map