I have used the calendly API inside my react component
I have tried with this code:
import React, { Component } from 'react'
import FullScreenModal from '../../../UIComponents/FullScreenModal'
export default class MeetingBooking extends Component {
state={
isLoading: false
}
componentDidMount() {
console.log(this.state.isLoading)
const head = document.querySelector('head');
const script = document.createElement('script');
script.setAttribute('src', 'https://assets.calendly.com/assets/external/widget.js');
head.appendChild(script);
this.setState({loading: false})
}
render() {
console.log(this.state.isLoading)
return (
<FullScreenModal open={this.props.open} title={"Book a Meeting"} handleClose={this.props.handleClose}>
{this.state.isLoading ?
<p>Loading...!!!!</p> :
<div
className="calendly-inline-widget"
data-url="https://calendly.com/kristofferlocktolboll"
style={{minWidth: '320px', height: '580px'}}>
</div>
}
</FullScreenModal>
)
}
}
the issue is that I can't await the request from the URL the same way I could with an Axios
or fetch API
request, so whenever the script is inserted, the loading component is not even shown.
So I'm looking for some way to listen to the injected javascript, and await it, so I can show my <p>Loading....!!!!</p>
in the meantime, can this be achieved?