0

I have the next code:

interface Interface<T> {
    submit: T,
    children: (ctx: { test: string, info: string }) => React.ReactNode | ReactElement;
}


const Test: React.FC<Interface<T>> = ({submit, children}) => {

    return (
        <div>
            {children({test: '123', info: '3'})}
        </div>
    )
}

How to add T here <Interface<T>?

1 Answer 1

3

React.FC can't be used to define a generic component. Fortunately, you don't really need React.FC, you can just make the function generic ands specify the type of the props on the parameter:


const Test = <T,>({submit, children}: Interface<T>) => {

    return (
        <div>
            {children({test: '123', info: '3'})}
        </div>
    )
}

Playground Link

Sign up to request clarification or add additional context in comments.

1 Comment

could you please help here stackoverflow.com/questions/74474194/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.