Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

useState does not set value in react under `useCallBack` [duplicate]

$
0
0

I have one local variable that is controlled by useState that should be set after calling useCallback. However, after debug I do not see the info is set. Looking for different solution in stackoverflow. but still do not know how to fix it

import { useCallback, useState } from "react";import "./styles.css";export default function App() {  const [info, setInfo] = useState<object>({});  const handleOnClick = useCallback(() => {    console.log(info);//{}    setInfo({ name: "name1", address: "1234" });    console.log(info);//{}  }, [info]);  return (<div className="App"><button onClick={handleOnClick}>Hello</button></div>  );}

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>