ReactContainer.tsx 849 B

1234567891011121314151617181920212223242526272829303132333435
  1. import React from 'react';
  2. import ReactDOM from 'react-dom';
  3. import coreModule from 'app/core/core_module';
  4. import { store } from 'app/stores/store';
  5. import { Provider } from 'mobx-react';
  6. function WrapInProvider(store, Component, props) {
  7. return (
  8. <Provider {...store}>
  9. <Component {...props} />
  10. </Provider>
  11. );
  12. }
  13. /** @ngInject */
  14. export function reactContainer($route, $location, backendSrv) {
  15. return {
  16. restrict: 'E',
  17. template: '',
  18. link(scope, elem) {
  19. let component = $route.current.locals.component;
  20. let props = {
  21. backendSrv: backendSrv,
  22. };
  23. ReactDOM.render(WrapInProvider(store, component, props), elem[0]);
  24. scope.$on('$destroy', function() {
  25. ReactDOM.unmountComponentAtNode(elem[0]);
  26. });
  27. },
  28. };
  29. }
  30. coreModule.directive('reactContainer', reactContainer);