showNotification in react-admin doesn't work

人走茶凉 提交于 2019-12-24 08:07:08

问题


1. Call from lifecycle callbacks. I have the code like bellow:

// app.js
<Admin>
   <Resource name="FooList" list={FooList} />
</Admin>

// FooList.js
class FooList extends React.Component {
     componentDidMount () {
         showNotification("foo")
     }
}

export default connect(null, {showNotification})(FooList)

When component get mounted, an error in console appeared:

 Warning: React does not recognize the `showNotification` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `shownotification` instead. If you accidentally passed it from a parent component, remove it from the DOM element.

2. Call on some event (e.g. click). In other case I have some handler and call showNotification in it.

class Foo extends React.component {
   handleClick = () => {
      showNotification('Hello, World')
   }
}

export default connect(null, { showNotification })(Foo)

In this case handleClick is called, but notification doesn't appeared, but there are NO errors in console

Bellow is my dependencies of the project

"dependencies": {
  "@material-ui/core": "1.5.1",
  "@material-ui/icons": "3.0.1",
  "apollo-boost": "^0.1.22",
  "apollo-link-schema": "^1.1.2",
  "graphql": "^14.0.2",
  "graphql-tag": "^2.10.0",
  "graphql-tag.macro": "^2.0.0",
  "graphql-tools": "^4.0.3",
  "graphql.macro": "^1.0.2",
  "material-ui": "^0.20.2",
  "ra-core": "^2.4.3",
  "ra-data-graphql": "^2.4.3",
  "react": "^16.3.2",
  "react-admin": "^2.4.3",
  "react-dom": "^16.3.3",
  "react-material-ui-form-validator": "^2.0.2",
  "react-scripts": "^2.1.1",
  "redux": "^4.0.1",
  "redux-thunk": "^2.3.0",
  "seamless-immutable": "^7.1.4"
}

How can I show notification in react-admin app? What I've missed?


回答1:


Action dispatchers are passed in as properties on the component, thus the name mapDispatchToProps. Therefore to call an action dispatcher, you would use this.props.showNotification('Hello, World')



来源:https://stackoverflow.com/questions/54062100/shownotification-in-react-admin-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!