InitializeApp.tsx 719 B

123456789101112131415161718192021222324252627282930
  1. import React from "react";
  2. import { LoadingMessage } from "./LoadingMessage";
  3. import { defaultLang, Language, languages, setLanguage } from "../i18n";
  4. interface Props {
  5. langCode: Language["code"];
  6. }
  7. interface State {
  8. isLoading: boolean;
  9. }
  10. export class InitializeApp extends React.Component<Props, State> {
  11. public state: { isLoading: boolean } = {
  12. isLoading: true,
  13. };
  14. async componentDidMount() {
  15. const currentLang =
  16. languages.find((lang) => lang.code === this.props.langCode) ||
  17. defaultLang;
  18. await setLanguage(currentLang);
  19. this.setState({
  20. isLoading: false,
  21. });
  22. }
  23. public render() {
  24. return this.state.isLoading ? <LoadingMessage /> : this.props.children;
  25. }
  26. }