render-props icon indicating copy to clipboard operation
render-props copied to clipboard

Update to support latest react features

Open heygrady opened this issue 6 years ago • 0 comments

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

heygrady avatar Feb 21 '19 23:02 heygrady