'Function in the component is getting called twice in react js

I am using useMemo react hook in the function component. I am not sure why the console log is getting twice printed. Here below is my code:

import './App.css';
import react,{useState,useMemo} from 'react';

function App() {

  const [count,setCount] = useState(0);
  const [item,setItem] = useState(10);

  const multiCountMemo = useMemo(function multiCount() {
    console.log("to check if getting inside the function")  <---- this is getting printed twice by default on load app page.
    return count * 5
  },[count])


  return (
    <div className="App">
      <h1>useMemo Hook Usage</h1>

      <h2>Count : {count}</h2>
      
      <h2>Item : {item}</h2>

      <h2>{multiCountMemo}</h2>

      <button onClick={() => setCount(count + 1)}>Update Count</button>
      
      <button onClick={() => setItem(item * 10)}>Update Item</button>
    </div>
  );
}

export default App;

enter image description here



Solution 1:[1]

Try something like this.

app.filter('toLocaleDecimal', ($filter) => {
  return function(input) {
    let number = Number(input);
    if (number && !Number.isNaN(number)) {
      return Number(number).toLocaleString('desired_locale');
    } else {
      return '00,00';
    }
  }
});

HTML: {{item.value | toLocaleDecimal}}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 naveen