@atlaskit/navigation-system
Version:
The latest navigation system for Atlassian apps.
30 lines (29 loc) • 1.37 kB
JavaScript
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import React, { useState } from 'react';
import { TopNavStartAttachRef } from './top-nav-start-attach-ref';
import { TopNavStartElement } from './top-nav-start-element';
/**
* Provider for the TopNavStart container element contexts.
*
* We are using a [ref callback](https://react.dev/reference/react-dom/components/common#ref-callback) along with a state
* for storing the element once it has mounted, so that the side nav can bind event listeners to the element
* once it is mounted.
*
* Otherwise, the side nav can be mounted before the element (e.g. if the element is lazy loaded), which would prevent the
* event listeners from being set up.
*
* State is required as opposed to just a ref so that the effects in the side nav can react to the element actually being mounted,
* as ref values cannot be added as effect dependencies.
*/
export var TopNavStartProvider = function TopNavStartProvider(_ref) {
var children = _ref.children;
var _useState = useState(null),
_useState2 = _slicedToArray(_useState, 2),
element = _useState2[0],
setElement = _useState2[1];
return /*#__PURE__*/React.createElement(TopNavStartElement.Provider, {
value: element
}, /*#__PURE__*/React.createElement(TopNavStartAttachRef.Provider, {
value: setElement
}, children));
};