Skip to content

Commit

Permalink
Fix plotband to work when used outside of axis context
Browse files Browse the repository at this point in the history
  • Loading branch information
anajavi committed Sep 30, 2019
1 parent 01a4516 commit 9e3ccd2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ 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
});
});

useEffect(() => {
return () => {
attempt(updatePlotBandLineLabel, plotbandline, {
if (!providedPlotbandline) return;
attempt(updatePlotBandLineLabel, providedPlotbandline.object, {
text: null
});
};
}, [plotbandline]);
}, [providedPlotbandline]);

return null;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9e3ccd2

Please sign in to comment.