-
Notifications
You must be signed in to change notification settings - Fork 27
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
context support #5
Comments
I think I ran into this problem today.. Tried to replicate how your toasts work in Sancho UI with my own render callback component + toasted-notes where is a custom component for displaying the notification.
It works as long as ANotif contains just a message with a div but breaks as soon as I add styled-components inside. Is this what you're referring to in this issue / do you know any workaround? Sancho and toasted-notes are great by the way! |
Hmm yeah, it'll break if you rely on theme variables with styled components. The key is to wrap your render callback with your theme, like so: function CustomAlert() {
<div>Custom</div>
}
const CustomAlertWithTheme = withTheme(CustomAlert)
toast.notify(() => <CustomAlertWithTheme /> I think one possible solution on our end (and something I've been a bit reluctant to do) is to provide a |
Huh, that's odd. I don't think this is related. It's indicating that the ref isn't being set for some reason and I'm not sure why that'd be the case. The ref should be referring to the |
Hello! Bumping this thing up. I wasn't able to use context properly. I want to use Apollo client inside a toast (this is GraphQL thing) so here's what I'm doing:
Now when I try to use this thing in my component tree, I use something like:
When I call showTaskInfo(taskComponent()), it does not work since withApollo requires a root div to be wrapped into a context provider named ApolloProvider. How can I wrap a notification root div in an ApolloProvider? I've been trying to do it like this...
but it still creates its own div with id |
Hey @pashazz! For starters, I'd probably recommend not doing any grapqhl fetching within the Having said that, you should be able to provide the import client from './path/to/client';
const Notification = () => (
<ApolloProvider client={client}>
{/* subscriptions or queries go here */}
</ApolloProvider>
);
toast.notify(<Notification />); I haven't actually tried this so your mileage may vary. I think one solution I might build to better support context is to provide an optional |
Thank you for your help. I've just done my GraphQL fetching that way:
My problem is that the div in here does not re-render when data in cache changes, except for the moment when it closes (when duration is not null, it actually rerenders just before closing). Any thoughts on how I can force rerender? This fetching code works just fine on a plain Component |
Yeah, I don't think the The Buuut, I'm honestly not sure. I've probably try the |
What do you mean exactly? I intend to update the UI of notification when my subscription updates. I use cache for that. If only I had a method to trigger an update of my notification UI from subscribe callback, It'd resolve my problems. I can probably call notify from subscribe callback but then Id have had many notification. Now if I could call notify that I replace an existing notification using some ID that I can provide, that'd be great |
Hey! Any chance we'll get first-hand Context support? Without the need to wrap the component? I'd be more than happy to contribute to this with a PR. |
I second this. First-hand context support would be awesome. It's the missing piece for me since I use this package with some translatable messages. |
hey all, I don't really have time to work on this currently. Happy to accept a PR 👍 |
Hello @bmcmahen! I will have a look at it in the next couple of days. Cheers 👍 |
Hello everyone. I had a look at it last night and have some questions. As far as I can tell, the context is missing because the |
That makes sense to me. I imagine you'd want something like <StyledComponentContextProvider>
<ToastProvider>
<App />
</ToastProvider>
</StyledComponentContextProvider> |
Given the current API, jsx in render props or elements won't get access to context. Explore ways to support context while maintaining the current API, and inform users of ways to supply context to their render callback (wrap it with context providers).
The text was updated successfully, but these errors were encountered: