A Higher Order Component using react-redux to keep dialog state in a Redux store
Inspired from suciuvlad/redux-dialog
Clone this repo then run:
npm install
npm start
The easiest way to use redux-reactstrap-modal is to install it from NPM and include it in your own React build process
npm install --save redux-reactstrap-modal
yarn add redux-reactstrap-modal
The first step is to combine the redux-reactstrap-modal reducer with your own application reducers
import {createStore, combineReducers} from 'redux';
import { dialogReducer } from 'redux-reactstrap-modal';
const reducers = {
// Other reducers here
dialogReducer: dialogReducer
}
const reducer = combineReducers(reducers);
const store = createStore(reducer);
Remark : dialogReducer
is the name used by the internal Wrapper to access to store, it cannot by renamed.
Decorate your component with reduxDialog.
import {connect} from 'react-redux';
import reduxDialog from 'redux-reactstrap-modal';
const BasicDialog = () => (
<div>
My awesome modalbox!
</div>
)
const Dialog = reduxDialog(
connect, // [NEW] needed to be compatible with react-redux > 6
{
name: 'signupDialog' // unique name - you can't have two dialogs with the same name
})(BasicDialog);
Use redux-reactstrap-modal's actions to show and hide the dialog
import { openDialog, closeDialog } from 'redux-reactstrap-modal';
const MyComponent = () => (
<a href="#" onClick={() => dispatch(openDialog('signupDialog'))}></a>
)
The reduxDialog method only requires the name property to work. The rest of the optional properties can be Any valid reactstraps's modal options.
A unique id for this dialog
A data object that will be passed to the modal as a property. Usefull to send data from the modal parent
The content wrapped inside the modal receive the additional props :
This will toggle the dialog. Can be used for buttons like Dismiss, Cancel, Close, ...
see the file : https://github.com/anis-campos/redux-reactstrap-modal/blob/develop/examples/index.js
Work in progress
What's new:
- SSR is supported
- Latest version of react, redux and reactstrap ( may 2019 )
Fixes
- Fix issue 5 : Incompatible with SSR
- fixing travis CI
- migrating from Karma to Jest
- Fix issue 6 : Incompatible with react-redux > 6
- need to pass
store
to create the redux wrapper
- Fix issue 4 : Uncaught TypeError: state.merge is not a function