Skip to content

Commit

Permalink
Remove react-dom/server dependency
Browse files Browse the repository at this point in the history
ReactDOMServer has been used to compare React components.
Such comparison is not necessary and therefore, the dependency
can be removed.
  • Loading branch information
bastian-src committed May 8, 2024
1 parent 3bb6004 commit cc40e85
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useState, useEffect, useCallback } from 'react';
import PropTypes from 'prop-types';
import {
Progress,
Expand Down Expand Up @@ -40,7 +40,8 @@ const UtilizationProgress = ({
else if (resourceUtilizationPercent < 100) return ProgressVariant.warning;
return ProgressVariant.danger;
};
const updateResourceUtilizationView = () => {

const updateResourceUtilizationView = useCallback(() => {
let newPercent;
let newTooltipText;

Expand Down Expand Up @@ -93,13 +94,14 @@ const UtilizationProgress = ({
</div>
);
}
if (resourceUtilizationPercent !== newPercent)
setResourceUtilizationPercent(newPercent);
if (!areReactElementsEqual(resourceUtilizationTooltipText, newTooltipText))
setResourceUtilizationTooltipText(newTooltipText);
};
setResourceUtilizationPercent(newPercent);
setResourceUtilizationTooltipText(newTooltipText);
}, [isNewQuota, resourceUnits, resourceUtilization, resourceValue]);

// call it once
updateResourceUtilizationView();
useEffect(() => {
updateResourceUtilizationView();
}, [updateResourceUtilizationView]);

return (
<div>
Expand Down
12 changes: 0 additions & 12 deletions webpack/helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import ReactDOMServer from 'react-dom/server';

/**
* Performs a deep equality comparison between two objects, including nested objects and arrays.
* @param {Object} obj1 - The first object to compare.
Expand Down Expand Up @@ -37,16 +35,6 @@ const deepEqual = (obj1, obj2) => {
return true;
};

const areReactElementsEqual = (element1, element2) => {
const elementToStr = element =>
element && ReactDOMServer.renderToStaticMarkup(element);

const element1Str = elementToStr(element1);
const element2Str = elementToStr(element2);

return element1Str === element2Str;
};

/**
* Recursively copies values from the source hash (`src`) to the destination hash (`dest`).
* Only keys that are a member of dest will copied from src.
Expand Down

0 comments on commit cc40e85

Please sign in to comment.