@fluentui/react-portal-compat-context
TypeScript icon, indicating that this package has built-in type declarations

9.0.13 • Public • Published

@fluentui/react-portal-compat-context

This package contains the React Context for compat layer in @fluentui/react-portal-compat.

Installation

yarn add @fluentui/react-portal-compat-context

Usage

Note: These APIs are intended to be used by library developers, please use @fluentui/react-portal-compat if you need Portal compatibility.

PortalCompatContextProvider and usePortalCompat() are exported APIs for implementing compat layer.

import { PortalCompatContextProvider, usePortalCompat } from '@fluentui/react-portal-compat-context';

function Consumer() {
  const registerEl = usePortalCompat();

  React.useEffect(() => {
    const portalEl = document.createElement('div');

    return registerEl(portalEl);
  }, [registerEl]);

  return null;
}

function App() {
  const registerEl = React.useCallback((portalEl: HTMLElement) => {
    // do something...
    console.log(portalEl);

    return () => {
      // do something for cleanups...
    };
  }, []);

  return (
    <PortalCompatContextProvider value={registerEl}>
      <Consumer />
    </PortalCompatContextProvider>
  );
}

Readme

Keywords

none

Package Sidebar

Install

npm i @fluentui/react-portal-compat-context

Weekly Downloads

115,714

Version

9.0.13

License

MIT

Unpacked Size

20.3 kB

Total Files

23

Last publish

Collaborators

  • sopranopillow
  • microsoft1es
  • justslone
  • chrisdholt
  • miroslavstastny
  • levithomason
  • uifabricteam
  • uifrnbot
  • dzearing
  • layershifter
  • ling1726
  • travisspomer