Skip to content

Instantly share code, notes, and snippets.

@yukoss
Last active September 22, 2017 13:20
Show Gist options
  • Save yukoss/9fe131d2af7816eaf8b1ad65c57e91cf to your computer and use it in GitHub Desktop.
Save yukoss/9fe131d2af7816eaf8b1ad65c57e91cf to your computer and use it in GitHub Desktop.
Clear error message action
// 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