Is there a working Typescript implementation of a useToast component anywhere? #6813
-
https://react-spectrum.adobe.com/react-aria/useToast.html#example
This is the provider shown in the example at the above link, but the types aren't complete (as is it complains about the state and children type). Demo here: https://codesandbox.io/p/sandbox/react-aria-toast-forked-6wf3c3?workspaceId=16c46381-55e3-4dc6-9eb6-dc5890e46a4d I know it's also partially a skill issue, but it really would help newer developers to React-Aria if these code snippets were actually working examples. Thanks, Nick *as a further example of why working code might be helpful: After the initial examples you get to a section that says:
But up until this point there's been no mention or no demonstration of wrapping the entire app, only multiple buttons. Sure wrapping the app is usually how Providers work, but wrapping a function returning a component, and in this case a simple button, definitely wasn't that clear for me and remains that way. I can't seem to implement this and haven't found an example showing me how to. It's a real shame as I'd love to continue using React-Aria! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
I've added some types here, the ToastProvider children and state wasn't typed at the top because it depends on what you will allow as the content for your Toasts as shown here: https://react-spectrum.adobe.com/react-aria/useToast.html#typescript. We could consider typing the code snippet you've mentioned in the docs, but I'm a bit concerned that people may then think that only the type we set there is allowed. As for wrapping an app, the intention is to have the rest of your app within the ToastProvider so that the state is passed down so anything in your app could access the toast state like here. We could perhaps have a more in depth example in the docs to make this clearer. |
Beta Was this translation helpful? Give feedback.
I've added some types here, the ToastProvider children and state wasn't typed at the top because it depends on what you will allow as the content for your Toasts as shown here: https://react-spectrum.adobe.com/react-aria/useToast.html#typescript. We could consider typing the code snippet you've mentioned in the docs, but I'm a bit concerned that people may then think that only the type we set there is allowed.
As for wrapping an app, the intention is to have the rest of your app within the ToastProvider so that the state is passed down so anything in your app could access the toast state like here. We could perhaps have a more in depth example in the docs to make this clearer.