-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[Core/Toast] Toaster.create() returns null #1688
Comments
Please provide code examples that repros and exact error messages |
@llorca apologies for the delay. The defined method import { Position, Toaster } from '@blueprintjs/core'
export const appNotification = dismissAction => Toaster.create({
className: 'app-toaster',
position: Position.TOP,
onDismiss: () => dismissAction()
}) The component import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { appNotification } from './utils/notification'
import Header from './components/Header'
import Footer from './components/Footer'
import { clearNotification } from './actions/app'
class Layout extends Component {
constructor(props) {
super(props)
this.state = {
toaster: null
}
}
componentDidMount() {
this.setState = {
toaster: appNotification(this.props.actions.clearNotification)
}
}
componentWillReceiveProps(nextProps) {
const { toaster } = this.state
const { app: { notification } } = this.props
const { app: { notification: nextNotification } } = nextProps
if (notification !== nextNotification) {
toaster && toaster.show(nextNotification)
}
}
render() {
const { app } = this.props
return (
<div>
<Header app={app} />
<div>
{this.props.children}
</div>
<Footer />
</div>
)
}
}
const mapStateToProps = state => ({
app: state.app
})
const mapDispatchToProps = dispatch => ({
actions: bindActionCreators({ clearNotification }, dispatch)
})
Layout.propTypes = {
children: PropTypes.any.isRequired,
app: PropTypes.object.isRequired,
actions: PropTypes.shape({
clearNotification: PropTypes.func
})
}
export default connect(mapStateToProps, mapDispatchToProps)(Layout) appNotification is always null, o calling cannot call method show on null |
|
^ @casoetan - yes, try this and let us know if it fixes your issue. |
@casoetan there are a number of bugs in your code, including the The expected usage is something like this:
Hope this helps! Please refactor your code and let us know if you can get it working. |
Oh it's also worth noting that calling Edit: All this to support my proposal of defining a Toaster at initialization time (i.e., |
@AlexLandau the set state was obviously from scratching my head for over 2 days trying to get what worked on React 15 to work on React 16. @giladgray you are quite right. In React 16, this would always return null. #facebook/react#10309 (comment). The Toaster does not work with SSR as it depends on the dom, reason I'm instantiating in ComponentDidMount. |
1 similar comment
@AlexLandau the set state was obviously from scratching my head for over 2 days trying to get what worked on React 15 to work on React 16. @giladgray you are quite right. In React 16, this would always return null. #facebook/react#10309 (comment). The Toaster does not work with SSR as it depends on the dom, reason I'm instantiating in ComponentDidMount. |
Solved with #1205 export const Toast = (typeof window !== 'undefined')
? Toaster.create({
className: 'my-toaster',
position: Position.BOTTOM_RIGHT
})
: null |
I am using a DIC for the toaster, so it calls it whenever its used for the first time. In this case its also returning |
Bug report
Steps to reproduce
Actual behavior
Toast does not show
Expected behavior
Toast to show
The text was updated successfully, but these errors were encountered: