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
This is useful for TypeScript when in an component you want to return a single array of elements but if you return just the arrayOfElements then the return type of the component becomes JSX.Element[] which when you use the component produces an error:
'Component' cannot be used as a JSX component.
Its return type 'Element[]' is not a valid JSX element.
Type 'Element[]' is missing the following properties from type 'ReactElement<any, any>': type, props, keyts(2786)
So wrapping the array with the fragment fixes the type error but causes the ESLint error, so enabling the allowExpressions option allows for this specific use case.
The text was updated successfully, but these errors were encountered:
The
react/jsx-no-useless-fragment
has aallowExpressions
configuration option that allows fragments that have a single expression in them like:This is useful for TypeScript when in an component you want to return a single array of elements but if you return just the
arrayOfElements
then the return type of the component becomesJSX.Element[]
which when you use the component produces an error:So wrapping the array with the fragment fixes the type error but causes the ESLint error, so enabling the
allowExpressions
option allows for this specific use case.The text was updated successfully, but these errors were encountered: