使用 rematch: redux 框架从模型构建存储时呈现 Notify(触发 onClick 的通知组件)组件时遇到问题。dispatch(createNotification(config))
正在触发但它没有更新状态。知道为什么吗?我的猜测是重新匹配框架没有正确绑定 notifyReducer。在 redux devtools 这就是我得到的:
行动:
ADD_NOTIFICATION // action being dispatched
type(pin): "ADD_NOTIFICATION"
notification:
message(pin): "THIS NOTIFICATION WORKS!"
type(pin): "SUCCESS"
duration(pin): 0
canDismiss(pin): true
icon: { ... }
id(pin): 1537900315811
状态:
Notifications: [] // not being updated when ADD_NOTIFICATIONS triggers
模型/通知.js
import notifyReducer from 'react-redux-notify'
export default {
state: [],
reducers: { notifyReducer },
}
store.js
import { init } from '@rematch/core'
import notifications as models from './models'
const store = init({ models })
export default store
容器/ExampleComponentContainer.js
import { connect } from 'react-redux'
import { createNotification } from 'react-redux-notify'
import ExampleComponent from '../../components/ExampleComponent'
import store from '../../store'
const { dispatch } = store
const mapStateToProps = ({ notifications }) => ({ notifications })
const mapDispatchToProps = ({}) => ({
createNotification: config => {
dispatch(createNotification(config))
},
})
export default connect(
mapStateToProps,
mapDispatchToProps,
)(ExampleComponent)
组件/示例组件
import { Notify, NOTIFICATION_TYPE_SUCCESS } from 'react-redux-notify';
class ExampleComponent extends React.Component {
successNotification = {
message: 'IT WORKS!',
type: NOTIFICATION_TYPE_SUCCESS,
duration: 0,
canDismiss: true,
icon: <i className="fa fa-check" />
}
handleClick = () => {
const {createNotification} = this.props;
createNotification(mySuccessNotification);
}
render(){
return (
<div>
<Notify />
<button onClick={this.handleClick()}>Dispatch Notification!
</button>
</div>
)
}
}