fix: add null checks for array mapping in TRPCDemo component

- Add optional chaining to sentimentDistribution?.map() to prevent runtime errors
- Add optional chaining to sessions?.sessions?.map() for consistency
- Both properties can be null/undefined and need protection before mapping
- Prevents 'Cannot read property map of undefined' errors
This commit is contained in:
2025-07-13 16:24:27 +02:00
parent 6d7619a9c5
commit efe0a3f79c

View File

@ -150,7 +150,7 @@ export function TRPCDemo() {
</div>
) : (
<div className="space-y-1">
{overview?.sentimentDistribution.map((item) => (
{overview?.sentimentDistribution?.map((item) => (
<div
key={item.sentiment}
className="flex justify-between text-sm"
@ -226,7 +226,7 @@ export function TRPCDemo() {
</div>
) : (
<div className="space-y-4">
{sessions?.sessions.map((session) => (
{sessions?.sessions?.map((session) => (
<div key={session.id} className="border rounded-lg p-4">
<div className="flex items-center justify-between mb-2">
<div className="flex items-center space-x-2">