An open API service indexing awesome lists of open source software.

https://github.com/activ8-developers/react-redux-flash-message

UI agnostic library that makes easy to create flash messages and to store them in a Redux store.
https://github.com/activ8-developers/react-redux-flash-message

flash-messages javascript react-redux redux

Last synced: about 1 month ago
JSON representation

UI agnostic library that makes easy to create flash messages and to store them in a Redux store.

Awesome Lists containing this project

README

        

# About

This is UI agnostic library that makes easy to create flash messages and to store them in a Redux store. This library does not render the FlashMessages for you it only stores them!

# Installation

`npm install simple-redux-flash-message --save`

# Getting started.
First add the following dependencies in the package.json (if present skip this step):

- "react-redux": "^6.0.1"
- "redux": "^4.0.4"

Now add the flash-message-reducer to your rootReducer, for example:

```javascript
import { combineReducers } from 'redux';
import { flashMessageReducer } from 'simple-redux-flash-message';

const rootReducer = combineReducers({
flashMessage: flashMessageReducer
});

export default rootReducer;
```

# Sending flash messages

Now that we can see the flash messages we can use the following convenience methods to send flash messages:

```javascript
import { publishFlashMessage } from 'simple-redux-flash-message';

const {dispatch} = this.props;

// Redux dispatch method
// Message text
// Number of miliseconds messages will be displayed
// On click callback
// Custom data passed to message
publishFlashMessage(dispatch, "This is message content", 5000, () => console.log("Message clicked!"), {"message-type": "warning"})

```

# Rendering flash messages

Put following component somewhere in app root and pass messages prop from redux store.

```javascript
import React, { Component } from 'react';

export class FlashMessage extends Component {

renderMessage(message) {
return (

message.onClick()}
>

Close

message.onClick()}>

{message.text}




);
}

render() {
const { messages } = this.props;

return (


{messages.map((message) => this.renderMessage(message))}

);
}
}

export default FlashMessage;
```