| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.ReportMainChartProps = void 0;
|
|---|
| 7 | var _react = require("react");
|
|---|
| 8 | var _PanoramaContext = require("../context/PanoramaContext");
|
|---|
| 9 | var _layoutSlice = require("./layoutSlice");
|
|---|
| 10 | var _hooks = require("./hooks");
|
|---|
| 11 | var _propsAreEqual = require("../util/propsAreEqual");
|
|---|
| 12 | /**
|
|---|
| 13 | * "Main" props are props that are only accepted on the main chart,
|
|---|
| 14 | * as opposed to the small panorama chart inside a Brush.
|
|---|
| 15 | */
|
|---|
| 16 |
|
|---|
| 17 | function ReportMainChartPropsImpl(_ref) {
|
|---|
| 18 | var {
|
|---|
| 19 | layout,
|
|---|
| 20 | margin
|
|---|
| 21 | } = _ref;
|
|---|
| 22 | var dispatch = (0, _hooks.useAppDispatch)();
|
|---|
| 23 |
|
|---|
| 24 | /*
|
|---|
| 25 | * Skip dispatching properties in panorama chart for two reasons:
|
|---|
| 26 | * 1. The root chart should be deciding on these properties, and
|
|---|
| 27 | * 2. Brush reads these properties from redux store, and so they must remain stable
|
|---|
| 28 | * to avoid circular dependency and infinite re-rendering.
|
|---|
| 29 | */
|
|---|
| 30 | var isPanorama = (0, _PanoramaContext.useIsPanorama)();
|
|---|
| 31 | /*
|
|---|
| 32 | * useEffect here is required to avoid the "Cannot update a component while rendering a different component" error.
|
|---|
| 33 | * https://github.com/facebook/react/issues/18178
|
|---|
| 34 | *
|
|---|
| 35 | * Reported in https://github.com/recharts/recharts/issues/5514
|
|---|
| 36 | */
|
|---|
| 37 | (0, _react.useEffect)(() => {
|
|---|
| 38 | if (!isPanorama) {
|
|---|
| 39 | dispatch((0, _layoutSlice.setLayout)(layout));
|
|---|
| 40 | dispatch((0, _layoutSlice.setMargin)(margin));
|
|---|
| 41 | }
|
|---|
| 42 | }, [dispatch, isPanorama, layout, margin]);
|
|---|
| 43 | return null;
|
|---|
| 44 | }
|
|---|
| 45 | var ReportMainChartProps = exports.ReportMainChartProps = /*#__PURE__*/(0, _react.memo)(ReportMainChartPropsImpl, _propsAreEqual.propsAreEqual); |
|---|