I am not really sure where I did wrong. I have one customized Hook that called with providing inputValue
. and one local variable value
initial Value is 0
. so after clicking button from component level, onNumberChange hook triggered and if value and input value is not the same. it should update value under hook by setValue
. However, after I place the debug under if (isNumberUpdate)
block. I can see value
stay the same as 0 if I clicking the button twice.
export function useNumberChange(inputValue) { const [value, setValue] = useState(0) const onNumberChange = useCallback(async (): Promise<void> => { const isNumberUpdate = isNumberDiff(inputValue, value); if (isNumberUpdate) { //console.log('debug') //console.log(value, inputValue) setValue(inputValue); } }, [inputValue, value]);//componentexport const Home: FC<{update:number}> = (props) => {const {updateValue} = props const {onNumberChange} = useNumberChange(updateValue) const handleOnClick = useCallBack(()=>{ onNumberChange() }) return (<div className="App"><button onClick={handleOnClick}>click</button></div> );}