Skip to content

Commit

Permalink
Merge branch 'hotfix-losingprops'
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel committed Oct 26, 2018
2 parents 4ca6833 + a90530b commit 6e41beb
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 10 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"react/jsx-no-bind": 2,
"react/no-multi-comp": 0,
"react/jsx-closing-tag-location": 0,
"react/jsx-one-expression-per-line": 0,
"arrow-body-style": 0,
"prefer-arrow-callback": 0,
"semi": 1,
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
### [Versions](https://github.com/thundermiracle/next-mui-helper/releases/)

## 1.1.1
###### *Oct 26, 2018*

#### Breaking Changes

N/A

#### Changes

- Fix the bug of makeNextApp.js losing props in hoc

## 1.1.0
###### *Oct 24, 2018*

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-mui-helper",
"version": "1.1.0",
"version": "1.1.1",
"description": "hocs for making material-ui project with next.js(SSR)",
"main": "./src/mui/withParts.js",
"scripts": {
Expand Down
17 changes: 15 additions & 2 deletions pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
import { DefaultNextApp } from '../src/nextjs/makeNextApp';
import React from 'react';

export default DefaultNextApp;
import makeNextApp from '../src/nextjs/makeNextApp';

const Layout = (props) => {
return (
<div>
[Layout]
<div>
{props.children}
</div>
</div>
);
};

export default makeNextApp(null, Layout);
15 changes: 9 additions & 6 deletions pages/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React from 'react';
import Button from '@material-ui/core/Button';
import { defaultParts } from '../src/mui/withParts';
import Link from 'next/link';

const Page1 = () => (
<Button color="primary">
Hello World
</Button>
const Index = () => (
<div>
<Button color="primary">Hello World</Button>
<Link href="/page1">
<Button>To Page1</Button>
</Link>
</div>
);

export default defaultParts(Page1);
export default Index;
14 changes: 14 additions & 0 deletions pages/page1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import Button from '@material-ui/core/Button';
import Link from 'next/link';

const Index = () => (
<div>
Page1 contentsssssssssssssss...
<Link href="/">
<Button>To Top</Button>
</Link>
</div>
);

export default Index;
16 changes: 15 additions & 1 deletion src/nextjs/makeNextApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,24 @@ import App, { Container } from 'next/app';
import withParts from '../mui/withParts';

const makeNextApp = (muiTheme, Layout, enableNProgress, enableDefaultCssBaseline) => {
const hocs = withParts(muiTheme, Layout, enableNProgress, enableDefaultCssBaseline);
class NextApp extends App {
// inject props made by hoc
static async getInitialProps({ Component, ctx }) {
let pageProps = {};

const ComponentWithInitialProps = hocs(Component);

if (ComponentWithInitialProps.getInitialProps) {
pageProps = await ComponentWithInitialProps.getInitialProps(ctx);
}

return { pageProps };
}

render() {
const { Component, pageProps } = this.props;
const NewComponent = withParts(muiTheme, Layout, enableNProgress, enableDefaultCssBaseline)(Component);
const NewComponent = hocs(Component);

return (
<Container>
Expand Down

0 comments on commit 6e41beb

Please sign in to comment.