render-props
render-props copied to clipboard
Update to support latest react features
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