Neverending Programming Mistakes
Miss any of our Open RFC calls?Watch the recordings here! »

@alexseitsinger/previous-pathname-middleware

0.1.0 • Public • Published

Previous Pathname Middleware

Description

Adds the previous pathname to router in redux store.

Usage

In store:

import { createStore, compose, applyMiddleware } from "redux"
import { routerMiddleware } from "connected-react-router"
import previousPathnameMiddleware from "@alexseitsinger/previous-pathname-middleware"
 
import createRootReducer from "../reducer"
 
function configureStore(history, initialState = {}) {
    const rootReducer = createRootReducer(history)
    const middleware = [previousPathnameMiddleware, routerMiddleware(history)]
    const storeEnhancers = compose(applyMiddleware(...middleware))
    const store = createStore(rootReducer, initialState, storeEnhancers)
    return store
}

In component:

import React from "react"
import PropTypes from "prop-types"
import { connect } from "react-redux"
 
function App({ previousPathname }) {
    return <div>App</div>
}
 
App.propTypes = {
    previousPathname: PropTypes.string.isRequired
}
 
const mapStateToProps = (state) => {
    return {
        previousPathname: state.router.previousPathname
    }
}
 
export default connect(mapStateToProps)(App)

Keywords

none

Install

npm i @alexseitsinger/previous-pathname-middleware

DownloadsWeekly Downloads

0

Version

0.1.0

License

BSD-2-Clause

Unpacked Size

73.5 kB

Total Files

5

Last publish

Collaborators

  • avatar