npm.io
2.0.1 • Published 8 years ago

react-redux-dialog

Licence
MIT
Version
2.0.1
Deps
2
Vulns
0
Weekly
0
Stars
2

react-redux-dialog

Travis npm Coveralls

Gracefully handle presenting Modal Dialogs via Redux. Leverages react-modal.

Installation

npm i -S react redux react-redux react-redux-dialog

Usage

Mount the reducer

The reducer must be mounted at 'modal'.

import { combineReducers } from 'redux';
import { reducer as modal } from 'react-redux-dialog';

export default combineReducers({ 
    modal,
    // ... other reducers
})

Mount the container

import { ModalContainer } from 'react-redux-dialog';
class App extends React.Component {
	render() {
		return (
			<div>
			    <ModalContainer />
			    {/* ... the rest of your component */}
            		</div>
		)
	}
}

Dispatch a modal via setModal

import { setModal } from 'react-redux-dialog';

setModal(AnyComponent, {
    componentProps: { /* Props your AnyComponent uses */ },
    modalProps: { ... }
})

And that's it! The ModalContainer will take care of the rest.

modalProps
Property type Required? Description
title string no A title for the modal, that will appear in the header
showClose [boolean=false] no Show a close button for the modal

Additionally any other valid prop that react-modal uses will be passed along to the internal Modal.

Keywords