Answer the question
In order to leave comments, you need to log in
Is it possible to specify which components can be passed to children?
Tell me, can I somehow specify which components can be passed to children.
Or is it only left to use the type children: React.ReactElement?
Answer the question
In order to leave comments, you need to log in
Anything can be passed to children. The question is how the component will use it.
For example, in the Render Props pattern, children are passed as a function.
// edit-response to comment
Somehow it should work.
import React from 'react';
interface MyComponentProps {
children: (items: string[]) => void;
regexp: RegExp;
items: string[];
}
export const MyComponent: React.FC<MyComponentProps> = ({ children, items, regexp }) => {
return children(items.filter(item => regexp.test(item)));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question