Skip to content
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

Ability to inject context... #37

Open
dehypnosis opened this issue Feb 7, 2018 · 3 comments
Open

Ability to inject context... #37

dehypnosis opened this issue Feb 7, 2018 · 3 comments

Comments

@dehypnosis
Copy link

dehypnosis commented Feb 7, 2018

I need to utilize context in content of Notification.
Can i retain the root component's context while using this component?

@dehypnosis
Copy link
Author

dehypnosis commented Feb 7, 2018

We are using Antd UI and MobX store, Apollo Graphql for React.
The problem is in Notification content (component), we cannot access store or apollo client..
This might be not a usual case, but for some one who might land here, i leave a workaround.

import Notification from 'rc-notification';
const renderNotification = Notification.prototype.render;
Notification.prototype.render = function() {
  return (
    <ApolloProvider client={apolloClient}>
      <StoreProvider store={store}>
        {renderNotification.call(this)}
      </StoreProvider>
    </ApolloProvider>
  )
}

By overriding Notification's render function, can access apollo or mobx in notification content.

Rc-notification may provide an option to utilize React portal to retain root component's context..

@yutingzhao1991
Copy link

Hmm... How about add feature like this:

import notification from 'rc-notification';

const NotificationContainer = notification.Container;

notification.setConfig({
  customContainer: true,
});

// ...

<ApolloProvider client={apolloClient}>
    <StoreProvider store={store}>
       <NotificationContainer />
    </StoreProvider>
</ApolloProvider>

related ant-design/ant-design#9036

@FoxxMD
Copy link

FoxxMD commented Apr 4, 2018

Also looking for this functionality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants