I have this code here. I keep getting an error:Cannot convert undefined or null to object (or sometimes TypeError: Cannot read property 'map' of undefined.)
Here is my code
const AdresList = (props) => { const [data, setData] = useState([]); const [isLoading, setIsLoading] = useState(false); useEffect(() => { setIsLoading(true); getXAddress() .then((response) => { const { data } = response || {}; setData(data); setIsLoading(false); }) .catch((error) => console.error(error)); }, []); return (<DashboardLayout> {isLoading && (<TableRow sx={{ my: "1rem", padding: "6px 18px" }}><Typography whiteSpace="pre" m={0.75} textAlign="left"><Skeleton variant="text" /></Typography><Typography flex="1 1 260px !important" m={0.75} textAlign="left"><Skeleton variant="text" /></Typography><Typography whiteSpace="pre" textAlign="right" color="grey.600"><Skeleton variant="text" /></Typography></TableRow> )} {data?.length > 0 && data.map((row) => (<TableRow sx={{ my: "1rem", padding: "6px 18px" }} key={row.id}><Typography whiteSpace="pre" m={0.75} textAlign="left"> {row.attributes.name}</Typography></TableRow> ))}</DashboardLayout> );};export default AdresList;
And the code of function
export const getXAddress = async () => { const response = await apiClient.get("/adress"); return response.data;};
I will be grateful for help.