Skip to content

Instantly share code, notes, and snippets.

@cpv123
Created December 21, 2019 17:44
Show Gist options
  • Save cpv123/d2ffcfb34c2789b04c373c59a9c98286 to your computer and use it in GitHub Desktop.
Save cpv123/d2ffcfb34c2789b04c373c59a9c98286 to your computer and use it in GitHub Desktop.
import React from 'react'
import { Iterable } from 'immutable'
export const toJS = WrappedComponent => wrappedComponentProps => {
const KEY = 0
const VALUE = 1
const propsJS = Object.entries(wrappedComponentProps).reduce(
(newProps, wrappedComponentProp) => {
newProps[wrappedComponentProp[KEY]] = Iterable.isIterable(
wrappedComponentProp[VALUE]
)
? wrappedComponentProp[VALUE].toJS()
: wrappedComponentProp[VALUE]
return newProps
},
{}
)
return <WrappedComponent {...propsJS} />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment