Skip to content

Update to support latest react features #7

@heygrady

Description

@heygrady

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions