79718458

Date: 2025-07-29 10:37:04
Score: 0.5
Natty:
Report link

when the iconId passed to Foo is invalid (for example, something like "foz" sent from the server), the entire application crashes

Since you have an components list with valid iconIds, you can simply check if the received iconId is valid or not as below:


// This will return undefined if no such iconId is present in the list
const iconData = components.find(c => c.iconId === iconId); 

// If no such iconId found
if (!iconData) return null; // Or <DefaultComponent />

// Else render actual component
return <ComponentToRender />;
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): when the
  • Low reputation (1):
Posted by: Shyam Butani