I am trying to get some data into a table. For that I am using react Map() function. But the variable is inside the function and I am unable to use it in map. What is the easiest way to use that variable in map.
This is my coding
import React, { useEffect } from 'react';
import { useDispatch } from 'react-redux';
import { getAllActivityDetails } from 'app/store/activityTracker/activitySlice';
const ActivityLog = () => {
const dispatch = useDispatch();
useEffect(() => {
getAllActivities();
}, []);
const getAllActivities = async () => {
const user = await JSON.parse(localStorage.getItem('user'));
const paramsData = {
_entity: 'ActivityTrack',
_select: '*',
channel: 'KOORS',
email: user && user.data && user.data.email ? user.data.email : ''
};
console.log('Email', user);
const res = await dispatch(getAllActivityDetails(paramsData));
console.log('res', res);
};
return (
<div className="flex flex-col mt-8">
<div className="py-2 -my-2 overflow-x-auto sm:-mx-6 sm:px-6 lg:-mx-8 lg:px-8">
<div className="inline-block min-w-full overflow-hidden align-middle border-b border-gray-200 shadow sm:rounded-lg">
<table className="min-w-full">
<thead>
<tr>
<th className="px-6 py-3 text-xs font-medium leading-4 tracking-wider text-left text-gray-100 uppercase border-b border-gray-200 bg-gray-50">
.
</th>
<th className="px-6 py-3 text-xs font-medium leading-4 tracking-wider text-left text-gray-900 uppercase border-b border-gray-200 bg-gray-50">
Actions
</th>
<th className="px-6 py-3 text-xs font-medium leading-4 tracking-wider text-left text-gray-900 uppercase border-b border-gray-200 bg-gray-50">
Users
</th>
</tr>
</thead>
<tbody className="bg-white">
{res.data.data.map(log => (
<tr>
<td className="px-6 py-4 whitespace-no-wrap border-b border-gray-200">
<div className="flex items-center">
<div className="ml-4">
<div className="text-sm font-medium leading-5 text-gray-600">
{log.userName}
</div>
<div className="text-sm font-medium leading-5 text-gray-800">
{log.createdAt}
</div>
</div>
</div>
</td>
<td className="px-6 py-4 whitespace-no-wrap border-b border-gray-200">
<div className="text-sm leading-5 text-gray-800">{log.activityCode}</div>
</td>
<td className="px-6 py-4 whitespace-no-wrap border-b border-gray-200">
<div className="text-sm leading-5 text-gray-800">{log.description}</div>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
);
};
export default ActivityLog;
I need to use the 'res' variable in the map. But it is showing as res is not defined.
This is the response I am getting[unable to share complete result]
Trying to do this since morning. If I create any outer variables, other functions related to this are changing. So how can I get the details in map without changing anything in the current code? Please help.
I just need to get the values of 'res' globally.

res, and how do you use it that it causes to fail. Please provide a minimal and reproduicble code.