redux-modal-container

0.3.0 • Public • Published

Redux-Modal-Container

Build Status redux-modal-container codecov

This library provides an easy way to show and hide modals when working with Redux.

Installation

To install the latest version:

npm install --save redux-modal-container

or

yarn add redux-modal-container

How to use

Create the modals entry point (Container component needs access to the Redux state):

import { Container as ModalContainer } from 'redux-modal-container';
// ...
render(
  <Provider store={yourStore}>
    <ModalContainer 
      modals={{
        simple: () => <div>Modal 1</div>,
      }}
    />
    <MyComponent />
  </Provider>,
  document.findElementById('root')
)

Combine the modal reducer:

import { modalReducer } from 'redux-modal-container';
// ...
export const rootReducer = combineReducers({
  modals: modalReducer,
});

Trigger the modal from your connected component:

import { showModal } from 'redux-modal-container';
// ...
 
class MyComponent extends React.Component {
  trigger = () => {
    this.props.showModal('simple');
  };
  render() {
    return (
      <div>
        <button onClick={this.trigger}>Open modal</button>
      </div>
    );
  }
}
 
export default connect(null, dispatch =>
  bindActionCreators({ showModal }, dispatch),
)(MyComponent);

A full example can be found in examples directory.

License

MIT

/redux-modal-container/

    Package Sidebar

    Install

    npm i redux-modal-container

    Weekly Downloads

    8

    Version

    0.3.0

    License

    MIT

    Unpacked Size

    51 kB

    Total Files

    44

    Last publish

    Collaborators

    • ionutmilica