Skip to content

Commit

Permalink
Allow render props(fkhadra#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
fkhadra committed Dec 17, 2017
1 parent bfd595b commit 801069f
Show file tree
Hide file tree
Showing 4 changed files with 1,909 additions and 6 deletions.
1,903 changes: 1,901 additions & 2 deletions dist/ReactToastify.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ReactToastify.min.js.map

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/ToastContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ class ToastContainer extends Component {
return (
isValidElement(content) ||
typeof content === 'string' ||
typeof content === 'number'
typeof content === 'number' ||
this.isFunction(content)
);
}

Expand Down Expand Up @@ -310,6 +311,8 @@ class ToastContainer extends Component {
content = cloneElement(content, {
closeToast
});
} else if (this.isFunction(content)) {
content = content({ closeToast });
}

this.collection = Object.assign({}, this.collection, {
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/ToastContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,15 @@ describe('ToastContainer', () => {
expect(component.state().toast).toHaveLength(0);
});

it('Should be able to render a react element, a string or a number without crashing', () => {
it('Should be able to render a react element, a string, a number, a render props without crashing', () => {
const component = mount(<ToastContainer />);
toaster('coucou');
toaster(123);
toaster(<div>plop</div>);
toaster(() => <div>plop</div>);
jest.runAllTimers();

expect(component.state().toast).toHaveLength(3);
expect(component.state().toast).toHaveLength(4);
});

it('Should be able to display new toast on top', () => {
Expand Down

0 comments on commit 801069f

Please sign in to comment.