Skip to content

Commit

Permalink
Fix console warning for component attribute type (#60)
Browse files Browse the repository at this point in the history
* Fix console warning for component attribute type

* Bump version
  • Loading branch information
icd2k3 authored Feb 12, 2019
1 parent 112a1c5 commit 0e1cb44
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
"object-curly-newline": 0,
"react/destructuring-assignment": 0,
"react/jsx-one-expression-per-line": 0
},
"globals": {
"jest": "writeable"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-router-breadcrumbs-hoc",
"version": "2.3.0",
"version": "2.3.2",
"description": "Just a tiny, flexible, higher order component for rendering breadcrumbs with react-router 4.x",
"repository": "icd2k3/react-router-breadcrumbs-hoc",
"keywords": [
Expand Down
19 changes: 18 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,24 @@ const NO_BREADCRUMB = 'NO_BREADCRUMB';
* Renders and returns the breadcrumb complete
* with `match`, `location`, and `key` props.
*/
const render = ({ breadcrumb, match, location, ...rest }) => {
const render = ({
/**
* extracting `component` here to avoid an invalid attribute warning
* see: https://github.com/icd2k3/react-router-breadcrumbs-hoc/issues/59
* This is actually a symptom of a larger issue with this current
* functionality of passing route data (needed for breadcrumb rendering)
* as props on the component itself. This has the unintended side-effect
* of rendering those props as element attributes in the DOM.
* TODO: Refactor this render logic (and probably the API) to not render
* those props as attributes on the breadcrumb element.
*/
component,

breadcrumb,
match,
location,
...rest
}) => {
const componentProps = { match, location, key: match.url, ...rest };
if (typeof breadcrumb === 'function') {
return createElement(breadcrumb, componentProps);
Expand Down
13 changes: 13 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,19 @@ describe('react-router-breadcrumbs-hoc', () => {
const { breadcrumbs } = render({ pathname: '/one/two/three', routes });
expect(breadcrumbs).toBe('Home / One / TwoCustom / ThreeCustom');
});

it('Should not produce a console warning for unsupported element attributes', () => {
// see: https://github.com/icd2k3/react-router-breadcrumbs-hoc/issues/59
global.console.error = jest.fn();
const routes = [
{ path: '/one', breadcrumb: 'OneCustom', component: () => <span>One Page</span> },
{ path: '/one/two', component: () => <span>Two Page</span> },
];
const { breadcrumbs } = render({ pathname: '/one/two', routes });
expect(breadcrumbs).toBe('Home / OneCustom / Two');
// eslint-disable-next-line no-console
expect(console.error).not.toHaveBeenCalled();
});
});

describe('Defaults', () => {
Expand Down

0 comments on commit 0e1cb44

Please sign in to comment.