npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

elm-react-redux

v1.0.0

Published

Elm wrapper for React-Redux

Downloads

5

Readme

elm-react-redux

Elm wrapper for a React-Redux application.
With this wrapper component you can simply embed Elm apps into React-Redux, dispatch actions and receive new props from React.

Usage

  1. Install with the package manager of your choice:
    npm install --save elm-react-redux or yarn add elm-react-redux

  2. Set up webpack to compile Elm for you:

{
      test: /\.elm$/,
      exclude: [/elm-stuff/, /node_modules/],
      loader: 'elm-webpack-loader',
}
  1. Create an Elm app somewhere inside your React project folder (src/elm is recommended)
  2. Import this wrapper and your Elm app:
import { Elm } from 'elm-react-redux'
import { Main } from '../elm/Main.elm'
  1. Use this component anywhere in your application
render() {
    return <Elm src={ Main } />
}

And you're good to go!

... of course you might want to use Redux. In that case you'll need to set up a few more things:

  1. The install process and webpack config is the same as above.
  2. Create an Elm app inside your React project folder. Your Elm app has to be a programWithFlags, this is how we pass the Redux state to Elm the first time it loads. Also, you'll need to write type definitions for your Redux State and use that as the type of the flag. Finally, you'll need set up the ports like this:
port stateChange : (ReduxData -> msg) -> Sub msg

port dispatch : { actions : List String, payload : List Value } -> Cmd msg

port jsAction : { object : String, method : String, payload : List Value } -> Cmd msg

I would recommend separating ports and redux data types to modules, like I did in the examples. 3. Import ElmWithRedux this wrapper and your Elm app

import { ElmWithRedux } from 'elm-react-redux'
import { Main } from '../elm/Main.elm'
  1. The ElmWithRedux component accepts a new actions attribute. This will enable our Elm app to use Redux action creators.
    We also have an optional convertState attribute, which accepts a converter function that will be applied to the state object coming from Redux. You can use this to narrow down the reducers, or convert some reducer to a different name.
<ElmWithRedux
    src={ Main }
    actions={ action }
    convertState={ state => state.someReducer }
/>

Converting states

Sometimes you will find yourself in a situation (like I did) when your Redux state object keys are invalid in Elm. Here's an example:

{
    warpReducer: {
        WW_001: 'Value1',
        WW_002: 'Value2'
    }
}

Capitalized first letters are not allowed in Elm as record keys, so this will cause an error. The solution for this is to write a stateConverter.

import { converter } from 'elm-react-redux'

const warpReducer = converter(/^W/, 'w')
const convertState = state => ({
    warpReducer: convertWarpReducer(state.warpReducer)
})

<ElmWithRedux
    src={ Main }
    actions={ action }
    convertState={ convertState }
/>

This will result in some nicer objects:

{
    warpReducer: {
        wW_001: 'Value1',
        wW_002: 'Value2'
    }
}

Under the hood it will do key.replace(oldkey, newkey) on all your object keys.

That would be it. If something is wrong, or you would like to see some new feature, please feel free to make an Issue!