Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to support latest react features #7

Open
heygrady opened this issue Feb 21, 2019 · 0 comments
Open

Update to support latest react features #7

heygrady opened this issue Feb 21, 2019 · 0 comments

Comments

@heygrady
Copy link

heygrady commented Feb 21, 2019

I was using this in a project based on the latest create-react-app and I was getting issues with arrow functions not having a prototype, which was causing the library to throw. It would be better to use react-is to check if the ComponentOrFunction is renderable with React.createElement.

import React from 'react'
import * as ReactIs from 'react-is'

const renderProps = (ComponentOrFunction, props) =>
  ReactIs.isValidElementType(ComponentOrFunction)
    ? React.createElement(ComponentOrFunction, props)
    : ComponentOrFunction({
        ...(ComponentOrFunction.defaultProps || {}),
        ...props,
      })

export default renderProps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant