@@ -33,11 +33,16 @@ export interface CollectionBuilderProps<C extends BaseCollection<object>> {
33
33
/**
34
34
* Builds a `Collection` from the children provided to the `content` prop, and passes it to the child render prop function.
35
35
*/
36
- export function CollectionBuilder < C extends BaseCollection < object > > ( props : CollectionBuilderProps < C > ) {
36
+ export function CollectionBuilder < C extends BaseCollection < object > > ( props : CollectionBuilderProps < C > ) : ReactElement {
37
37
// If a document was provided above us, we're already in a hidden tree. Just render the content.
38
38
let doc = useContext ( CollectionDocumentContext ) ;
39
39
if ( doc ) {
40
- return props . content ;
40
+ // The React types prior to 18 did not allow returning ReactNode from components
41
+ // even though the actual implementation since React 16 did.
42
+ // We must return ReactElement so that TS does not complain that <CollectionBuilder>
43
+ // is not a valid JSX element with React 16 and 17 types.
44
+ // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544
45
+ return props . content as ReactElement ;
41
46
}
42
47
43
48
// Otherwise, render a hidden copy of the children so that we can build the collection before constructing the state.
@@ -151,9 +156,9 @@ function useSSRCollectionNode<T extends Element>(Type: string, props: object, re
151
156
return < Type ref = { itemRef } > { children } </ Type > ;
152
157
}
153
158
154
- export function createLeafComponent < T extends object , P extends object , E extends Element > ( type : string , render : ( props : P , ref : ForwardedRef < E > ) => ReactNode ) : ( props : P & React . RefAttributes < T > ) => ReactNode | null ;
155
- export function createLeafComponent < T extends object , P extends object , E extends Element > ( type : string , render : ( props : P , ref : ForwardedRef < E > , node : Node < T > ) => ReactNode ) : ( props : P & React . RefAttributes < T > ) => ReactNode | null ;
156
- export function createLeafComponent < P extends object , E extends Element > ( type : string , render : ( props : P , ref : ForwardedRef < E > , node ?: any ) => ReactNode ) {
159
+ export function createLeafComponent < T extends object , P extends object , E extends Element > ( type : string , render : ( props : P , ref : ForwardedRef < E > ) => ReactElement ) : ( props : P & React . RefAttributes < T > ) => ReactElement | null ;
160
+ export function createLeafComponent < T extends object , P extends object , E extends Element > ( type : string , render : ( props : P , ref : ForwardedRef < E > , node : Node < T > ) => ReactElement ) : ( props : P & React . RefAttributes < T > ) => ReactElement | null ;
161
+ export function createLeafComponent < P extends object , E extends Element > ( type : string , render : ( props : P , ref : ForwardedRef < E > , node ?: any ) => ReactElement ) {
157
162
let Component = ( { node} ) => render ( node . props , node . props . ref , node ) ;
158
163
let Result = ( forwardRef as forwardRefType ) ( ( props : P , ref : ForwardedRef < E > ) => {
159
164
let isShallow = useContext ( ShallowRenderContext ) ;
@@ -171,7 +176,7 @@ export function createLeafComponent<P extends object, E extends Element>(type: s
171
176
return Result ;
172
177
}
173
178
174
- export function createBranchComponent < T extends object , P extends { children ?: any } , E extends Element > ( type : string , render : ( props : P , ref : ForwardedRef < E > , node : Node < T > ) => ReactNode , useChildren : ( props : P ) => ReactNode = useCollectionChildren ) {
179
+ export function createBranchComponent < T extends object , P extends { children ?: any } , E extends Element > ( type : string , render : ( props : P , ref : ForwardedRef < E > , node : Node < T > ) => ReactElement , useChildren : ( props : P ) => ReactNode = useCollectionChildren ) {
175
180
let Component = ( { node} ) => render ( node . props , node . props . ref , node ) ;
176
181
let Result = ( forwardRef as forwardRefType ) ( ( props : P , ref : ForwardedRef < E > ) => {
177
182
let children = useChildren ( props ) ;
0 commit comments