From 807810590e3fd436e9d033fa4c8a7a9ec251b463 Mon Sep 17 00:00:00 2001 From: Mathias Desloges Date: Thu, 26 Oct 2017 23:06:46 +0200 Subject: [PATCH] clean code --- src/PageManager.js | 57 +++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/src/PageManager.js b/src/PageManager.js index 0f09a19..6d12d9f 100644 --- a/src/PageManager.js +++ b/src/PageManager.js @@ -43,43 +43,42 @@ export class PageManager extends Component { const pages = routes.filter(r => !r.props.noNavbar).map(r => ({ name: r.props.name, path: r.props.path })) const navbars = children.filter(child => child.type === NavigationBar) + const renderPages = (pages) => pages.map((page, i) => { + const { exact, path, ...props } = page.props + return ( + React.cloneElement(page, { ...props })} /> + ) + }) + return ( - = 0 ? "right" : "left")}> - -
- - { - animatedPages.map(page => { - const { exact, path, ...props } = page.props - return ( - React.cloneElement(page, { ...props })} /> - ) - }) - } - -
-
+
+ = 0 ? "right" : "left")}> + +
+ + { + renderPages(animatedPages) + } + +
+
+
{ - notAnimatedPages.map(page => { - const { exact, path, ...props } = page.props - return ( - React.cloneElement(page, { ...props })} /> - ) - }) + renderPages(notAnimatedPages) }
- { navbars.map((navbar) => { - return React.cloneElement(navbar, { pages }) + { navbars.map((navbar, k) => { + return React.cloneElement(navbar, { pages, key: k }) }) } - +
); } }