i set the users state with axios data but in useEffect hook whereevery i console.log(users) its show the default state that is [] array. please see the comment for better undarstand.
let [users, setUsers] = useState([]);
useEffect(() => {
axios.get('/chat_user_list').then((res) => {
setUsers(res.data);
});
let pusher = new Pusher('api-key-over-here', {
cluster: 'ap1',
authEndpoint: "/admin/broadcasting/auth",
auth: {
headers: {
"X-CSRF-Token": csrfToken,
"Accept": "application/json"
},
},
});
let channel = pusher.subscribe(`presence-room`);
channel.bind("pusher:member_added", (member) => {
//how can i get the updated users state value over here
console.log(users); //set the users with axios data but it still return the default state; that is an [] array
});
}, []);