source: node_modules/recharts/lib/state/SetGraphicalItem.js@ a762898

Last change on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 2.2 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.SetCartesianGraphicalItem = void 0;
7exports.SetPolarGraphicalItem = SetPolarGraphicalItem;
8var _react = require("react");
9var _hooks = require("./hooks");
10var _graphicalItemsSlice = require("./graphicalItemsSlice");
11var SetCartesianGraphicalItemImpl = props => {
12 var dispatch = (0, _hooks.useAppDispatch)();
13 var prevPropsRef = (0, _react.useRef)(null);
14 (0, _react.useLayoutEffect)(() => {
15 if (prevPropsRef.current === null) {
16 dispatch((0, _graphicalItemsSlice.addCartesianGraphicalItem)(props));
17 } else if (prevPropsRef.current !== props) {
18 dispatch((0, _graphicalItemsSlice.replaceCartesianGraphicalItem)({
19 prev: prevPropsRef.current,
20 next: props
21 }));
22 }
23 prevPropsRef.current = props;
24 }, [dispatch, props]);
25 (0, _react.useLayoutEffect)(() => {
26 return () => {
27 if (prevPropsRef.current) {
28 dispatch((0, _graphicalItemsSlice.removeCartesianGraphicalItem)(prevPropsRef.current));
29 /*
30 * Here we have to reset the ref to null because in StrictMode, the effect will run twice,
31 * but it will keep the same ref value from the first render.
32 *
33 * In browser, React will clear the ref after the first effect cleanup,
34 * so that wouldn't be an issue.
35 *
36 * In StrictMode, however, the ref is kept,
37 * and in the hook above the code checks for `prevPropsRef.current === null`
38 * which would be false so it would not dispatch the `addCartesianGraphicalItem` action again.
39 *
40 * https://github.com/recharts/recharts/issues/6022
41 */
42 prevPropsRef.current = null;
43 }
44 };
45 }, [dispatch]);
46 return null;
47};
48var SetCartesianGraphicalItem = exports.SetCartesianGraphicalItem = /*#__PURE__*/(0, _react.memo)(SetCartesianGraphicalItemImpl);
49function SetPolarGraphicalItem(props) {
50 var dispatch = (0, _hooks.useAppDispatch)();
51 (0, _react.useLayoutEffect)(() => {
52 dispatch((0, _graphicalItemsSlice.addPolarGraphicalItem)(props));
53 return () => {
54 dispatch((0, _graphicalItemsSlice.removePolarGraphicalItem)(props));
55 };
56 }, [dispatch, props]);
57 return null;
58}
Note: See TracBrowser for help on using the repository browser.