react-admin中的showNotification不起作用

时间:2019-01-06 13:43:04

标签: reactjs react-redux react-admin

1。从生命周期回调中调用。 我有下面的代码:

// 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)

安装组件后,控制台出现错误:

 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。呼叫某个事件(例如,单击)。在其他情况下,我有一些处理程序,并在其中调用showNotification

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

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

在这种情况下,将调用handleClick,但没有出现通知,但控制台中没有错误

同胞是我对项目的依赖

"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"
}

如何在react-admin应用程序中显示通知? 我错过了什么?

1 个答案:

答案 0 :(得分:2)

动作分派器作为属性传递到组件上,因此名为mapDispatchToProps。因此,要调用动作分派器,您可以使用this.props.showNotification('Hello, World')