Created
December 21, 2019 17:44
-
-
Save cpv123/d2ffcfb34c2789b04c373c59a9c98286 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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