question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

option.formattingFn rerender

See original GitHub issue

i hope to change option.formattingFn to rerender if i changed it’s inner params .

const countUpProps = {
 start: start, 
 end: end,
 duration: duration ,
 separator: separator,
 decimals: decimals,
 delay: 0,
 formattingFn: formatNumber // dynamic function
};

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:16

github_iconTop GitHub Comments

1reaction
mmarkelovcommented, Jun 29, 2021

In your opinion is it possibile to prevent the animation and just re-run the formattingFn when needed somehow?

I’ll check it, not sure

For what cocerns prefix and suffix not applied in this case should I open another issue

Also will check it, but i suppose it’s just similar to CountUp behaviour.

1reaction
mmarkelovcommented, Jun 29, 2021

@Luc9802 just published 4.4.0 and it should work with redraw option:

import "./styles.css";
import CountUp from "react-countup";
import React, { useState } from "react";

const lngs = ["en", "it"];
export default function App() {
  const [lngIdx, setLngIdx] = useState(0);

  const changeLanguage = () => {
    setLngIdx((prevLngIdx) => (prevLngIdx === 0 ? 1 : 0));
  };

  return (
    <div className="App">
      <CountUp
        end={1650.25}
        decimals={2}
        prefix="test"
        suffix="test"
        redraw
        formattingFn={(val) => {
          return new Intl.NumberFormat(lngs[lngIdx]).format(val);
        }}
      />
      <br />
      <button onClick={changeLanguage}>CHANGE LANGUAGE</button>
    </div>
  );
}

And i’ll investigate the case with passing new formattingFn option.

Read more comments on GitHub >

github_iconTop Results From Across the Web

option.formattingFn rerender - Bountysource
Coming soon: A brand new website interface for an even better experience!
Read more >
glennreyes/react-countup - GitHub
formattingFn : (value: number) => string. Function to customize the formatting of the number. To prevent component from unnecessary updates this function should ......
Read more >
Rerender select element with a default option from parent ...
I have a select component, which calls a callback given by a parent component to change a state maintained by the parent. This...
Read more >
How to stop re-rendering lists in React? - Alex Sidorenko
Components always re-render. First, let's simplify our example by removing all props from the Item . We will still update the parent state...
Read more >
React re-renders guide: everything, all at once - Developer way
Re-render happens when React needs to update the app with some new data. Usually, this happens as a result of a user interacting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found