You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/src/pages/index.mdx
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1174,16 +1174,16 @@ An exaggerated example where implementing 10 React components with 5 required pr
1174
1174
When applicable use **discriminated type** to eliminate optional props, which will decrease complexity on component API and only required props will be passed depending on its use case.
1175
1175
1176
1176
```ts
1177
-
// ❌ Avoid optional props as they increase complexity of component API
1177
+
// ❌ Avoid optional props as they increase complexity and ambiguity in component APIs
1178
1178
typeStatusProps= {
1179
1179
data?:Products;
1180
1180
title?:string;
1181
1181
time?:number;
1182
1182
error?:string;
1183
1183
};
1184
1184
1185
-
// ✅ Strive to have majority of props required, if that's not possible,
1186
-
// use discriminated union for clear intent on component usage
1185
+
// ✅ Prefer required props. If optional props are unavoidable,
1186
+
// use a discriminated union to represent distinct use cases with required props.
1187
1187
typeStatusSuccess= {
1188
1188
status:'success';
1189
1189
data:Products;
@@ -1200,7 +1200,7 @@ type StatusError = {
1200
1200
error:string;
1201
1201
};
1202
1202
1203
-
// Discriminated component props 'StatusProps' with no optional properties
1203
+
// Discriminated union 'StatusProps' ensures predictable component props with no optionals
0 commit comments