fix: Add null checks to prevent 'Cannot read properties of null' errors
This commit is contained in:
@@ -7,7 +7,7 @@ interface CountriesProps {
|
||||
}
|
||||
|
||||
export default function Countries({ countries }: CountriesProps) {
|
||||
if (countries.length === 0) {
|
||||
if (!countries || countries.length === 0) {
|
||||
return (
|
||||
<div className="bg-white dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-800 rounded-xl p-6">
|
||||
<h3 className="text-lg font-semibold mb-4 text-neutral-900 dark:text-white">
|
||||
|
||||
@@ -7,7 +7,7 @@ interface TopPagesProps {
|
||||
}
|
||||
|
||||
export default function TopPages({ pages }: TopPagesProps) {
|
||||
if (pages.length === 0) {
|
||||
if (!pages || pages.length === 0) {
|
||||
return (
|
||||
<div className="bg-white dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-800 rounded-xl p-6">
|
||||
<h3 className="text-lg font-semibold mb-4 text-neutral-900 dark:text-white">
|
||||
|
||||
@@ -7,7 +7,7 @@ interface TopReferrersProps {
|
||||
}
|
||||
|
||||
export default function TopReferrers({ referrers }: TopReferrersProps) {
|
||||
if (referrers.length === 0) {
|
||||
if (!referrers || referrers.length === 0) {
|
||||
return (
|
||||
<div className="bg-white dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-800 rounded-xl p-6">
|
||||
<h3 className="text-lg font-semibold mb-4 text-neutral-900 dark:text-white">
|
||||
|
||||
@@ -19,9 +19,10 @@ export default function SiteList() {
|
||||
try {
|
||||
setLoading(true)
|
||||
const data = await listSites()
|
||||
setSites(data)
|
||||
setSites(Array.isArray(data) ? data : [])
|
||||
} catch (error: any) {
|
||||
toast.error('Failed to load sites: ' + (error.message || 'Unknown error'))
|
||||
setSites([]) // Ensure sites is always an array
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user