final-form / final-form/react-final-form

[Feature] Improve renderComponent

Open
#786 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.4k
Forks
497
PR merge metrics
No merged PRs in 30d

Description

The `renderComponent` function could use the react isValidElement and cloneElement functions for more flexibility (like recharts).

```js
// before
if (component) {
return React.createElement(
component,
Object.assign(lazyProps, rest, {
children,
render
})
)
}

// after
if (component) {
const elemProps = Object.assign(lazyProps, rest, {
children,
render
});

return React.isValidElement(component)
? React.cloneElement(component, elemProps) // merge props
: React.createElement(component, elemProps)
}
```

What allows to do:

```jsx

} />

} />
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.