with-google-key.component.jsx 678 B

123456789101112131415161718192021222324252627
  1. import React from "react";
  2. import { getGoogleApiKey } from "../services/ggsh.service";
  3. import Loading from "./loading.component";
  4. const withGoogleApiKey = ComposedComponent =>
  5. class extends React.Component {
  6. constructor(props) {
  7. super(props);
  8. this.state = { googleApiKey: null }
  9. }
  10. async componentDidMount() {
  11. const googleApiKey = await getGoogleApiKey();
  12. this.setState({ googleApiKey });
  13. }
  14. render() {
  15. const { googleApiKey } = this.state;
  16. if (!googleApiKey) {
  17. return <Loading/>
  18. }
  19. return <ComposedComponent {...this.props} googleApiKey={googleApiKey} />
  20. }
  21. }
  22. export default withGoogleApiKey;