ManageIQ/manageiq-ui-classic

View on GitHub
app/javascript/miq-component/react-blueprint.jsx

Summary

Maintainability
A
0 mins
Test Coverage
import * as React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';

export default (ReactElement, mapPropsToInteract = () => undefined) => {
  function render(props, container) {
    ReactDOM.render(
      <Provider store={ManageIQ.redux.store}>
        <ReactElement {...props} />
      </Provider>,
      container
    );
  }

  return {
    create(props, mountTo) {
      render(props, mountTo);
      return { interact: mapPropsToInteract(props), elementId: mountTo.id };
    },

    update(newProps, mountedTo) {
      render(newProps, mountedTo);
    },

    destroy(instance, unmountFrom) {
      ReactDOM.unmountComponentAtNode(unmountFrom);
    },

    component: ReactElement,
  };
}