score:1

export default function Test(props) {
  const [state, setState] = useState({
    data: []
  });

  useEffect(() => {
    getConnectionUsers("Test")
    return () => {alert("component unmount");}
  }, []);

  function getConnectionUsers(connection) {
    axios.get(URL).then((response) => {
        if (response.status === 200) {
          console.log(response.data);  // This is showing correct data which is coming from API
          setState({...state ,data:response.data});
          console.log(state.data);    //Empty State is coming which means somehow state is not updated properly
        }
    }).catch(error => {
        alert(error)
    });
  }  
}

Related Query

More Query from same tag