Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating props passed to chart appends new chart instead of replacing. #126

Open
TaylorBelk1 opened this issue Jan 9, 2023 · 0 comments

Comments

@TaylorBelk1
Copy link

When you change props that are passed to the gauge, it appends a new chart instead of replacing the chart with the new one with new prop values. You end up with infinite charts on the page eventually.

The project I am working on uses a drop down menu, when you select a list item, a new chart is added. But it should replace the current gauge values with the new ones passed in.

Code:

export const Gauge: React.FC<IProps> = ({
  id,
  currentNumber,
  maxNumber,
  styleOverrides,
}) => {

  const getPercentage = (num: number, percentOf: number) => {
    const percent = (num / 100) * percentOf;
    if (percent > 1) return 1;
    return percent;
  };

  console.log(id)
  return (
    <>
      <GaugeChart
        id={id}
        nrOfLevels={maxNumber}
        percent={getPercentage(currentNumber ? currentNumber : 0, maxNumber)}
        textColor="#000"
        style={styleOverrides ? { ...styleOverrides } : { width: "100%" }}
        hideText={true}
      />
    </>
  );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant