0.3.0 • Published 7 years ago

redux-modal-container v0.3.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

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

0.3.0

7 years ago

0.2.0

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.0

7 years ago