Skip to content

feat: allow extra args in render props #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/__tests__/render.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {createElement as h} from 'react';
import render from '../render';
import {mount} from 'enzyme';

const Parent = (props) => render(props, {foo: 'bar'});
const Parent = (props) => render(props, {foo: 'bar'}, 'extra1', 'extra2');

describe('render()', () => {
it('exists', () => {
Expand Down Expand Up @@ -41,6 +41,17 @@ describe('render()', () => {
expect(wrapper.html()).toBe('<div>bar</div>');
});

it('supports multiple arguments for render props', () => {
const wrapper = mount(
<Parent>{(state, arg1, arg2) => {
expect(arg1).toBe('extra1');
expect(arg2).toBe('extra2');

return <div>...</div>;
}}</Parent>
);
});

it('supports component prop interface', () => {
const MyComp = jest.fn();

Expand Down
4 changes: 2 additions & 2 deletions src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {createElement as h, cloneElement, version} from 'react';
const isReact16Plus = parseInt(version.substr(0, version.indexOf('.'))) > 15;
const isFn = fn => typeof fn === 'function';

const render = (props, data) => {
const render = (props, data, ...more) => {
if (process.env.NODE_ENV !== 'production') {
if (typeof props !== 'object') {
throw new TypeError('renderChildren(props, data) first argument must be a props object.');
Expand All @@ -30,7 +30,7 @@ const render = (props, data) => {

const {render, children = render, component, comp = component} = props;

if (isFn(children)) return children(data);
if (isFn(children)) return children(data, ...more);

if (comp) {
if (process.env.NODE_ENV !== 'production') {
Expand Down