// frontend (onClick function)
const handleOnClick = () => {
const data = api();
// do the work
// API
const api = () => {
var value;
// ask for data
socket.emit("ask-for-data");
// get respond from database
socket.on("get-response", (data) => {
value = data; //<- value is correct right here
//respond from API
return { value }; //<- value is undefined
// frontend (onClick function)
const handleOnClick = async () => {
const data = await api();
// do the work
// API
const api = async () => {
var value;
// ask for data
socket.emit("ask-for-data");
// get respond from database
await socket.on("get-response", (data) => {
value = data; //<- value is correct right here
//respond from API
return { value }; //<- value is undefined