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