journal.pl/src/index.tsx
Primakov Alexandr Alexandrovich 65216843ac
All checks were successful
platform/bro/pipeline/head This commit looks good
3.1.0
2024-08-11 23:55:48 +03:00

37 lines
973 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 './ym';
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();
};