Skip to content

Commit

Permalink
feat: react hook
Browse files Browse the repository at this point in the history
  • Loading branch information
hubcarl committed Mar 27, 2020
1 parent 576f4a0 commit 3f33ba7
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
5 changes: 1 addition & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@
"array-bracket-spacing": "off",
"no-unused-expressions": "off",
"linebreak-style": "off",
"func-style": [
"error",
"expression"
],
"func-style": "off",
"comma-dangle": [
"error",
"never"
Expand Down
8 changes: 8 additions & 0 deletions app/controller/example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ module.exports = app => {
text: 'React Stateless Component Server Render'
});
}

async reactHook() {
const { ctx } = this;
await ctx.render('example/hook.js', {
text: 'React Hook Component Server Render'
});
}


};
};
1 change: 1 addition & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = app => {
router.get('/csr', controller.blog.index.csr);
router.get('/node', controller.blog.index.node);
router.get('/example/stateless', controller.example.index.statelessRender);
router.get('/example/hook', controller.example.index.reactHook);
router.get('/example/async', controller.example.index.asyncComponentRender);
router.get('/example/data/node', controller.example.data.nodeDataRender);
router.get('/example/data/async', controller.example.data.asyncDataRender);
Expand Down
1 change: 1 addition & 0 deletions app/web/page/blog/router/example.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class Example extends Component {
};
return <div>
<h2 style={{...styleTitle}}>Egg React Example</h2>
<h4 style={{...styleSub}}><a target="_blank" href="/example/hook">React Hook Render</a></h4>
<h4 style={{...styleSub}}><a target="_blank" href="/example/async">React Async Component Render</a></h4>
<h4 style={{...styleSub}}><a target="_blank" href="/example/stateless">React Stateless Component Render</a></h4>
<h4 style={{...styleSub}}><a target="_blank" href="/example/data/node">React Server Render for Node Data Mode</a></h4>
Expand Down
23 changes: 23 additions & 0 deletions app/web/page/example/hook.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { useState } from 'react';

import request from '../../framework/request';
import Layout from 'component/layout';

function HookAsyncDataMode(props) {
const [data] = useState({
title: props.title,
article: props.article
});
return (<Layout>
<h2 className="easy-article-detail-title">{data.article.title}</h2>
<div className="easy-article-info">
<iframe src={data.article.url} frameBorder="0" width="100%" style={{minHeight: '800px'}}></iframe>
</div>
</Layout>);
}

HookAsyncDataMode.asyncData = async function(locals) {
return request.get('/example/data/api/article', locals);
}

export default HookAsyncDataMode;
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ module.exports = {
async: 'app/web/page/example/async/index.jsx',
'example/stateless': 'app/web/page/example/stateless.js',
'example/node': 'app/web/page/example/node.jsx',
'example/data': 'app/web/page/example/data.jsx'
'example/data': 'app/web/page/example/data.jsx',
'example/hook': 'app/web/page/example/hook.jsx'
},
plugins:[
{ imagemini: false },
Expand Down

0 comments on commit 3f33ba7

Please sign in to comment.