Files
journal.pl/src/index.tsx
Primakov Alexandr Alexandrovich fb267a11f9
Some checks failed
platform/bro/pipeline/head This commit looks good
platform/gitea-bro-js/journal.pl/pipeline/head There was a failure building this commit
platform/bro-js/journal.pl/pipeline/head This commit looks good
remove comment
2024-08-07 23:37:45 +03:00

36 lines
958 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './app';
import { keycloak } from "./__data__/kc";
import { createStore } from "./__data__/store";
export default (props) => <App {...props} />;
let rootElement: ReactDOM.Root
export const mount = async (Сomponent, element = document.getElementById('app')) => {
let user = null;
try {
await keycloak.init({ onLoad: "login-required" });
user = { ...(await keycloak.loadUserInfo()), ...keycloak.tokenParsed };
} catch (error) {
console.error("Failed to initialize adapter:", error);
keycloak.login();
}
const store = createStore({ user });
const rootElement = ReactDOM.createRoot(element);
rootElement.render(<Сomponent store={store} />);
if(module.hot) {
module.hot.accept('./app', ()=> {
rootElement.render(<Сomponent store={store} />);
})
}
};
export const unmount = () => {
rootElement.unmount();
};