import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import { App } from "./app";
ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
const options: InitOptions = {
acceptScrollbarStyle: true,
checkCompat: true,
debug: true
};
const AppWrapped = withSDK(Root);
export function App() {
return (
<SDKProvider initOptions={options}>
<AppWrapped />
</SDKProvider>
);
}
/**
* This component is the layer controlling the application display. It displays
* application in case, the SDK is initialized, displays an error if something
* went wrong, and a loader if the SDK is warming up.
*/
function Loader({children}: PropsWithChildren<{}>) {
const {didInit, components, error} = useSDK();
// There were no calls of SDK's init function. It means, we did not
// even try to do it.
if (!didInit) {
return <div>SDK init function is not yet called.</div>;
}
// Error occurred during SDK init.
if (error !== null) {
return <div>Something went wrong.</div>;
}
// If components is null, it means, SDK is not ready at the
// moment and currently initializing. Usually, it takes like
// several milliseconds or something like that, but we should
// have this check.
if (components === null) {
return <div>Warming up SDK.</div>;
}
// Safely render application.
return <>{children}</>;
}
export function Root({ sdk }) {
return (
<Loader>
<div>TEST app</div>
</Loader>
)
}
Loader gets stuck at Warming up SDK.
When console logging the sdk:
{components: null, didInit: true, error: null}