Skip to content

Commit bf00586

Browse files
maciejmyslinskierikras
authored andcommitted
Pass render prop when component is used (#55)
* Pass render prop when component is used * Improve test name
1 parent d1e249e commit bf00586

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/renderComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default function renderComponent<T>(
1111
): React.Node {
1212
const { render, children, component, ...rest } = props
1313
if (component) {
14-
return React.createElement(component, { ...rest, children }) // inject children back in
14+
return React.createElement(component, { ...rest, children, render })
1515
}
1616
if (render) {
1717
return render({ ...rest, children }) // inject children back in

src/renderComponent.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import renderComponent from './renderComponent'
2+
3+
describe('renderComponent', () => {
4+
it('should pass both render and children prop', () => {
5+
const children = 'some children'
6+
const render = () => 'examplary render function'
7+
const props = {
8+
component: () => null,
9+
children,
10+
render
11+
}
12+
const name = 'TestComponent'
13+
const result = renderComponent(props, name)
14+
expect(result.props).toEqual({ children, render })
15+
})
16+
})

0 commit comments

Comments
 (0)