Coder Social home page Coder Social logo

redux-modal's Introduction

Redux Modal

Greenkeeper badge

Build Status

redux-modal connect your modal to the redux store, and let you control your modal by simply dispatching actions.

It works with any react based modal component.

Live demo

Installation

npm i --save redux-modal

API

connectModal(config)

Connect a modal component to redux store.

Arguments

  • config(Object)
    • name(String)(Require) The modal name.
    • resolve(Function) Things you want to resolve before show your modal, if return a promise, the modal will show after the promise resolved.
    • destroyOnHide(Bool) Whether destroy the modal state and umount the modal after hide, default is true.
    • getModalState(Function) A function that takes the entire Redux state and returns the state slice which corresponds to where the redux-modal reducer was mounted. Defaults to assuming that the reducer is mounted under the 'modal' key.

Returns

A React component class that injects modal state, handleHide and handleDestroy action creator into your modal component.

Examples

export default connectModal({ name: 'myModal' })(MyModal)

It will pass the modal state and a handleHide and handleDestroy action creator as props to your modal component.

If you mounted your modal reducer at some other location such as modals instead of modal use the getModalState config

export default connectModal({ name: 'myModal', getModalState: (state) => state.modals })(MyModal)

reducer

The modal reducer. Should be given to mounted to your Redux state at modal.

Example

import { combineReducers } from 'redux'
import { reducer as modal } from 'redux-modal'

export default combineReducers({
  ...yourOtherReducers,
  modal
})

show(name, props) | show(name, props: T)

The show modal action creator.

Arguments

  • name(String) The name of modal to show.
  • props(Object) Props pass to your modal.

Example

import { MyModalProps } from '...'

show<MyModalProps>('modalName', {prop1: 'example'})

hide(name)

The hide modal action creator.

Arguments

  • name(String) The name of modal to hide.

License

MIT

redux-modal's People

Contributors

yesmeck avatar greenkeeper[bot] avatar burtek avatar apacheex avatar pkeuter avatar darmody avatar dpikt avatar gnoff avatar kubami avatar leo-esaki avatar max-kuzmenko avatar shicholas avatar skwon-mdsol avatar quolpr avatar shanehandley avatar ygist avatar paranoidjk avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.