-
-
Notifications
You must be signed in to change notification settings - Fork 700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to pass props to a custom component in TypeScript #568
Comments
This is more of a workaround than an answer, but I do it like this: function renderContent(text: string): JSX.Element {
return <div><p>{text}</p></div>;
}
const content = renderContent('Ooops');
toast(content); |
I thought of such a workaround too. But I want to be able to use the |
@stanleyk does the following solve your issue ? |
@fkhadra Yes, great, thank you! For future readers (I noticed the CodeSandbox examples disappear after some time): Declaring the component props using the Partial utility type helps:
|
@stanleyk thanks for testing. I guess this should be added to the documentation. |
Just providing another implementation example as I was looking for this but I had to tweak it a bit.
|
That should 100% be added to the documentation, the documentation for the current TS example is impossible to follow for a real-world use case. |
According to the docs I can create my own component and use it like this:
toast(<Msg />)
But when I create the component just like the docs suggest:
I get the (pretty obvious) error:
I can get it working by using the
toast(Msg)
form, but how do I pass anything (like the actual text I want to show) to the component in such case?
Maybe I am missing something essential here, thanks for any help!
The text was updated successfully, but these errors were encountered: