Skip to content

Commit 946143a

Browse files
authored
feat: add support for React.memo wrapped components (#67)
* feat: add support for React.memo wrapped components * chore: bump version
1 parent 5ff7261 commit 946143a

File tree

5 files changed

+50
-24
lines changed

5 files changed

+50
-24
lines changed

.eslintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"rules": {
66
"object-curly-newline": 0,
77
"react/destructuring-assignment": 0,
8-
"react/jsx-one-expression-per-line": 0
8+
"react/jsx-one-expression-per-line": 0,
9+
"react/jsx-filename-extension": 0,
10+
"react/no-multi-comp": 0
911
},
1012
"globals": {
1113
"jest": "writeable"

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-router-breadcrumbs-hoc",
3-
"version": "3.1.1",
3+
"version": "3.1.2",
44
"description": "Just a tiny, flexible, higher order component for rendering breadcrumbs with react-router 4.x",
55
"repository": "icd2k3/react-router-breadcrumbs-hoc",
66
"keywords": [
@@ -41,8 +41,8 @@
4141
"eslint-plugin-react": "^7.10.0",
4242
"jest": "^24.5.0",
4343
"prop-types": "^15.7.2",
44-
"react": "16.8.4",
45-
"react-dom": "16.8.4",
44+
"react": "16.8.6",
45+
"react-dom": "16.8.6",
4646
"react-router": "^5.0.0",
4747
"react-router-dom": "^5.0.0",
4848
"rollup": "^1.7.0",

src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
*/
2020

21-
import { createElement } from 'react';
21+
import React, { createElement } from 'react';
2222
import { matchPath, withRouter } from 'react-router';
2323

2424
const DEFAULT_MATCH_OPTIONS = { exact: true };
@@ -40,7 +40,7 @@ const humanize = str => str
4040
*/
4141
const render = ({
4242
component: reactRouterConfigComponent,
43-
breadcrumb,
43+
breadcrumb: Breadcrumb,
4444
match,
4545
location,
4646
...rest
@@ -49,9 +49,9 @@ const render = ({
4949

5050
return {
5151
...componentProps,
52-
breadcrumb: typeof breadcrumb === 'function'
53-
? createElement(breadcrumb, componentProps)
54-
: createElement('span', { key: componentProps.key }, breadcrumb),
52+
breadcrumb: typeof Breadcrumb === 'string'
53+
? createElement('span', { key: componentProps.key }, Breadcrumb)
54+
: <Breadcrumb {...componentProps} />,
5555
};
5656
};
5757

src/index.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ const components = {
3030
</span>
3131
),
3232
BreadcrumbExtraPropsTest: ({ foo, bar }) => <span>{foo}{bar}</span>,
33+
BreadcrumbMemoized: React.memo(() => <span>Memoized</span>),
34+
// eslint-disable-next-line react/prefer-stateless-function
35+
BreadcrumbClass: class BreadcrumbClass extends React.PureComponent {
36+
render() { return (<span>Class</span>); }
37+
},
3338
};
3439

3540
const getHOC = () => {
@@ -162,6 +167,20 @@ describe('react-router-breadcrumbs-hoc', () => {
162167
});
163168
});
164169

170+
describe('Different component types', () => {
171+
it('Should render memoized components', () => {
172+
const routes = [{ path: '/memo', breadcrumb: components.BreadcrumbMemoized }];
173+
const { breadcrumbs } = render({ pathname: '/memo', routes });
174+
expect(breadcrumbs).toBe('Home / Memoized');
175+
});
176+
177+
it('Should render class components', () => {
178+
const routes = [{ path: '/class', breadcrumb: components.BreadcrumbClass }];
179+
const { breadcrumbs } = render({ pathname: '/class', routes });
180+
expect(breadcrumbs).toBe('Home / Class');
181+
});
182+
});
183+
165184
describe('Custom match options', () => {
166185
it('Should allow `strict` rule', () => {
167186
const routes = [

yarn.lock

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4459,21 +4459,26 @@ rc@^1.2.7:
44594459
minimist "^1.2.0"
44604460
strip-json-comments "~2.0.1"
44614461

4462-
react-dom@16.8.4:
4463-
version "16.8.4"
4464-
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.8.4.tgz#1061a8e01a2b3b0c8160037441c3bf00a0e3bc48"
4465-
integrity sha512-Ob2wK7XG2tUDt7ps7LtLzGYYB6DXMCLj0G5fO6WeEICtT4/HdpOi7W/xLzZnR6RCG1tYza60nMdqtxzA8FaPJQ==
4462+
react-dom@16.8.6:
4463+
version "16.8.6"
4464+
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.8.6.tgz#71d6303f631e8b0097f56165ef608f051ff6e10f"
4465+
integrity sha512-1nL7PIq9LTL3fthPqwkvr2zY7phIPjYrT0jp4HjyEQrEROnw4dG41VVwi/wfoCneoleqrNX7iAD+pXebJZwrwA==
44664466
dependencies:
44674467
loose-envify "^1.1.0"
44684468
object-assign "^4.1.1"
44694469
prop-types "^15.6.2"
4470-
scheduler "^0.13.4"
4470+
scheduler "^0.13.6"
44714471

4472-
react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.4:
4472+
react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.4:
44734473
version "16.8.4"
44744474
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.4.tgz#90f336a68c3a29a096a3d648ab80e87ec61482a2"
44754475
integrity sha512-PVadd+WaUDOAciICm/J1waJaSvgq+4rHE/K70j0PFqKhkTBsPv/82UGQJNXAngz1fOQLLxI6z1sEDmJDQhCTAA==
44764476

4477+
react-is@^16.8.1:
4478+
version "16.8.6"
4479+
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16"
4480+
integrity sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA==
4481+
44774482
react-router-dom@^5.0.0:
44784483
version "5.0.0"
44794484
resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-5.0.0.tgz#542a9b86af269a37f0b87218c4c25ea8dcf0c073"
@@ -4513,15 +4518,15 @@ react-test-renderer@^16.0.0-0:
45134518
react-is "^16.8.4"
45144519
scheduler "^0.13.4"
45154520

4516-
react@16.8.4:
4517-
version "16.8.4"
4518-
resolved "https://registry.yarnpkg.com/react/-/react-16.8.4.tgz#fdf7bd9ae53f03a9c4cd1a371432c206be1c4768"
4519-
integrity sha512-0GQ6gFXfUH7aZcjGVymlPOASTuSjlQL4ZtVC5YKH+3JL6bBLCVO21DknzmaPlI90LN253ojj02nsapy+j7wIjg==
4521+
react@16.8.6:
4522+
version "16.8.6"
4523+
resolved "https://registry.yarnpkg.com/react/-/react-16.8.6.tgz#ad6c3a9614fd3a4e9ef51117f54d888da01f2bbe"
4524+
integrity sha512-pC0uMkhLaHm11ZSJULfOBqV4tIZkx87ZLvbbQYunNixAAvjnC+snJCg0XQXn9VIsttVsbZP/H/ewzgsd5fxKXw==
45204525
dependencies:
45214526
loose-envify "^1.1.0"
45224527
object-assign "^4.1.1"
45234528
prop-types "^15.6.2"
4524-
scheduler "^0.13.4"
4529+
scheduler "^0.13.6"
45254530

45264531
read-pkg-up@^2.0.0:
45274532
version "2.0.0"
@@ -4895,10 +4900,10 @@ sax@^1.2.4:
48954900
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
48964901
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
48974902

4898-
scheduler@^0.13.4:
4899-
version "0.13.4"
4900-
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.13.4.tgz#8fef05e7a3580c76c0364d2df5e550e4c9140298"
4901-
integrity sha512-cvSOlRPxOHs5dAhP9yiS/6IDmVAVxmk33f0CtTJRkmUWcb1Us+t7b1wqdzoC0REw2muC9V5f1L/w5R5uKGaepA==
4903+
scheduler@^0.13.4, scheduler@^0.13.6:
4904+
version "0.13.6"
4905+
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.13.6.tgz#466a4ec332467b31a91b9bf74e5347072e4cd889"
4906+
integrity sha512-IWnObHt413ucAYKsD9J1QShUKkbKLQQHdxRyw73sw4FN26iWr3DY/H34xGPe4nmL1DwXyWmSWmMrA9TfQbE/XQ==
49024907
dependencies:
49034908
loose-envify "^1.1.0"
49044909
object-assign "^4.1.1"

0 commit comments

Comments
 (0)