Back to all reviewers

provide defaults when destructuring

SigNoz/signoz
Based on 2 comments
TSX

When destructuring properties from objects that might contain undefined values, use the nullish coalescing operator (??) to provide explicit default values at the point of assignment. This prevents undefined values from propagating through your code and eliminates the need for repeated null checks later.

Null Handling TSX

Reviewer Prompt

When destructuring properties from objects that might contain undefined values, use the nullish coalescing operator (??) to provide explicit default values at the point of assignment. This prevents undefined values from propagating through your code and eliminates the need for repeated null checks later.

Instead of destructuring and handling nulls separately:

const { showIP } = params;
// Later in code: showIP ?? true

Provide the default immediately:

const showIP = params.showIP ?? true;

This pattern ensures that variables always have defined values, making your code more predictable and reducing the likelihood of null reference errors. Apply this approach consistently when accessing potentially undefined object properties, API responses, or configuration values.

2
Comments Analyzed
TSX
Primary Language
Null Handling
Category

Source Discussions