From 9e3ccd29bc47f92140925d785453153d1af36729 Mon Sep 17 00:00:00 2001 From: Antti Lehto Date: Mon, 30 Sep 2019 19:45:59 +0300 Subject: [PATCH] Fix plotband to work when used outside of axis context --- .../src/components/PlotBandLine/PlotBandLineLabel.js | 10 ++++++---- .../PlotBandLine/UsePlotBandLineLifecycle.js | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/react-jsx-highcharts/src/components/PlotBandLine/PlotBandLineLabel.js b/packages/react-jsx-highcharts/src/components/PlotBandLine/PlotBandLineLabel.js index 4ab26e34..2061e924 100644 --- a/packages/react-jsx-highcharts/src/components/PlotBandLine/PlotBandLineLabel.js +++ b/packages/react-jsx-highcharts/src/components/PlotBandLine/PlotBandLineLabel.js @@ -3,11 +3,12 @@ import { attempt } from 'lodash-es'; import usePlotBandLine from './UsePlotBandLine'; const PlotBandLineLabel = memo(props => { - const { object: plotbandline } = usePlotBandLine(); + const providedPlotbandline = usePlotBandLine(); useEffect(() => { + if (!providedPlotbandline) return; const { children: text, id, ...rest } = props; - updatePlotBandLineLabel(plotbandline, { + updatePlotBandLineLabel(providedPlotbandline.object, { text, ...rest }); @@ -15,11 +16,12 @@ const PlotBandLineLabel = memo(props => { useEffect(() => { return () => { - attempt(updatePlotBandLineLabel, plotbandline, { + if (!providedPlotbandline) return; + attempt(updatePlotBandLineLabel, providedPlotbandline.object, { text: null }); }; - }, [plotbandline]); + }, [providedPlotbandline]); return null; }); diff --git a/packages/react-jsx-highcharts/src/components/PlotBandLine/UsePlotBandLineLifecycle.js b/packages/react-jsx-highcharts/src/components/PlotBandLine/UsePlotBandLineLifecycle.js index fdabc7c4..7685594a 100644 --- a/packages/react-jsx-highcharts/src/components/PlotBandLine/UsePlotBandLineLifecycle.js +++ b/packages/react-jsx-highcharts/src/components/PlotBandLine/UsePlotBandLineLifecycle.js @@ -4,10 +4,10 @@ import { attempt } from 'lodash-es'; import useModifiedProps from '../UseModifiedProps'; import useAxis from '../UseAxis'; -export default function usePlotBandLine(props, plotType) { - const { id = uuid, children, ...rest } = props; +export default function usePlotBandLineLifecycle(props, plotType) { + const { id = uuid, axisId, children, ...rest } = props; - const axis = useAxis(); + const axis = useAxis(axisId); const idRef = useRef(); const [plotbandline, setPlotbandline] = useState(null); const modifiedProps = useModifiedProps(rest);