Last active
September 22, 2017 13:20
-
-
Save yukoss/9fe131d2af7816eaf8b1ad65c57e91cf to your computer and use it in GitHub Desktop.
Clear error message action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Update in Action/message.js | |
function clearErrorMessage() { | |
return { type: 'CLEAR_ERROR_MESSAGE', message: '' } | |
} | |
export { errorMessage, clearErrorMessage } | |
// Update import | |
import { errorMessage, clearErrorMessage } from '../../Actions/message'; | |
// Update connect | |
const ProductList = connect( | |
null, | |
{ errorMessage, clearErrorMessage } | |
)(ProductListComponent); | |
export { ProductList }; | |
// Update Reducers/message.js | |
export default (state = defaultState, { type, message }) => { | |
switch (type) { | |
case 'ERROR_MESSAGE': | |
return update(state, { text: { $set: message }, type: { $set: 'error' } }); | |
case 'CLEAR_ERROR_MESSAGE': | |
return update(state, { text: { $set: message }, type: { $set: 'clear' } }); | |
default: | |
return state; | |
} | |
}; | |
// Insert in constructor | |
this.props.clearErrorMessage(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment