@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
17 lines • 796 B
JavaScript
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import React from 'react';
import { fg } from '@atlaskit/platform-feature-flags';
export var useElementWidth = function useElementWidth(ref, _ref) {
var skip = _ref.skip;
var _React$useState = React.useState(undefined),
_React$useState2 = _slicedToArray(_React$useState, 2),
elementWidth = _React$useState2[0],
setWidth = _React$useState2[1];
React.useEffect(function () {
if (!skip && ref.current && !fg('platform_editor_prevent_toolbar_width_reflow')) {
// eslint-disable-next-line @atlassian/perf-linting/no-chain-state-updates -- Ignored via go/ees017 (to be fixed)
setWidth(Math.round(ref.current.getBoundingClientRect().width));
}
}, [skip, setWidth, ref]);
return elementWidth;
};