I the next code I have this problem with Small component because always is print two time, even when the component is created first time
App.js
import { useCounter } from "../Hooks/useCounter";
import { Small } from "./Small";
export const Memorize = () => {
const {counter, increment} = useCounter(10)
return(
<>
<Small value={counter}/>
<button
onClick={event => increment()}>
+1
</button>
</>
)
}
useCounter.js The counter value is working fine...
import { useState } from "react";
export const useCounter = (initialValue = 0) => {
const [counter, setCounter] = useState(initialValue)
const increment = (value = 1) => setCounter(counter + value)
return {
counter,
increment,
setCounter
}
}
Small.js ... here the problem or I dont know...
export const Small = ({value}) => {
console.log('Iam console log...');
return (
<small>{value}</small>
)
}
... each time that I do click in button +1 this console is print:
Iam console log...
Iam console log...
... I try to envolve with memo but doesnt works... any ideas ?