Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

33 строки
1.0 KiB

  1. import PropTypes from 'prop-types';
  2. import ReactDOM from 'react-dom';
  3. import useWaitForDOMRef from './utils/useWaitForDOMRef';
  4. var propTypes = {
  5. /**
  6. * A DOM element, Ref to an element, or function that returns either. The `container` will have the Portal children
  7. * appended to it.
  8. */
  9. container: PropTypes.any,
  10. onRendered: PropTypes.func
  11. };
  12. /**
  13. * The `<Portal/>` component renders its children into a new "subtree" outside of current component hierarchy.
  14. * You can think of it as a declarative `appendChild()`, or jQuery's `$.fn.appendTo()`.
  15. * The children of `<Portal/>` component will be appended to the `container` specified.
  16. *
  17. */
  18. var Portal = function Portal(_ref) {
  19. var container = _ref.container,
  20. children = _ref.children,
  21. onRendered = _ref.onRendered;
  22. var resolvedContainer = useWaitForDOMRef(container, onRendered);
  23. return resolvedContainer ? ReactDOM.createPortal(children, resolvedContainer) : null;
  24. };
  25. Portal.displayName = 'Portal';
  26. Portal.propTypes = propTypes;
  27. /**
  28. * @component
  29. */
  30. export default Portal;