-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
luoxue
committed
Dec 21, 2019
1 parent
af8b425
commit 02bcb12
Showing
7 changed files
with
69 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +0,0 @@ | ||
// import React from 'react'; | ||
// export default class App extends React.Component{ | ||
// render() { | ||
// return ( | ||
// <div> | ||
// Hello, World! | ||
// </div> | ||
// ) | ||
// } | ||
// } | ||
|
||
import React, { useState, useReducer } from 'react' | ||
|
||
const myReducer = (state, action) => { | ||
console.log(action, 'action') | ||
console.log(state, 'state') | ||
switch (action.type) { | ||
case ('countUp'): | ||
return { | ||
...state, | ||
count: action.count | ||
} | ||
default: | ||
return state | ||
} | ||
} | ||
|
||
const arr = [[{ a: 1 }], [{ a: 4 }, { a: 5 }, { a: 6 }], [{ a: 7 }, { a: 8 }]] | ||
const item = arr.map((cur, index) => { | ||
return <div key={index.toString()} style={{ margin: '20px', backgroundColor: 'cyan' }}> | ||
{ | ||
cur.map((item, idx) => { | ||
return <p key={idx.toString()}>{item.a}</p> | ||
}) | ||
} | ||
</div> | ||
}) | ||
|
||
export const App = () => { | ||
const [btnText, setBtnText] = useState('Click me, please') | ||
const [state, dispatch] = useReducer(myReducer, { count: 0 }) | ||
|
||
function handleClick() { | ||
return setBtnText(btnText === 'Click me, please' ? 'Thanks, been clicked!' : 'Click me, please') | ||
} | ||
|
||
return <div> | ||
<button onClick={handleClick}>{btnText}</button> | ||
<div> | ||
<button onClick={() => dispatch({ type: 'countUp', count: state.count + 1 })}> | ||
+1 | ||
</button> | ||
<p>Count: {state.count}</p> | ||
</div> | ||
<div style={{ display: 'flex' }}> | ||
{item} | ||
</div> | ||
</div> | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,21 @@ | ||
// import TS from './ts/index.ts' | ||
// tree-shaking | ||
import { cube } from '@src/treeShaking' | ||
import { App } from '../packages/react/index' | ||
import React from 'react' | ||
import ReactDom from 'react-dom' | ||
|
||
console.log(cube(2)) | ||
// 动态加载ts | ||
import('@src/ts/index.ts').then(res => { | ||
console.log(res) | ||
// eslint-disable-next-line new-cap | ||
new res.default() | ||
}) | ||
require('./style/index.css') | ||
require('./style/app.css') | ||
require('./style/index.less') | ||
require('./style/index.scss') | ||
import('./style/index.postcss') | ||
require('react') | ||
// 加载图片 | ||
const myPubPic = require('./assets/my-pub.jpeg') | ||
ReactDom.render(<App/>, document.getElementById('app')) | ||
// 测试环境变量 | ||
if (process.env.NODE_ENV === 'production') { | ||
console.log('Welcome to production') | ||
} | ||
console.log(cube(2)) | ||
console.log(myPubPic) | ||
|
||
// 加载样式 | ||
require('./style') | ||
const h2 = document.createElement('h2') | ||
h2.className = 'test' | ||
h2.innerText = 'webpack 5' | ||
document.body.append(h2) | ||
// 加载react | ||
require('./react') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from 'react' | ||
import ReactDom from 'react-dom' | ||
import { App } from './template' | ||
|
||
ReactDom.render(<App/>, document.getElementById('app')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, { useState, useReducer } from 'react' | ||
|
||
const myReducer = (state, action) => { | ||
console.log(action, 'action') | ||
console.log(state, 'state') | ||
switch (action.type) { | ||
case ('countUp'): | ||
return { | ||
...state, | ||
count: action.count | ||
} | ||
default: | ||
return state | ||
} | ||
} | ||
|
||
const arr = [[{ a: 1 }], [{ a: 4 }, { a: 5 }, { a: 6 }], [{ a: 7 }, { a: 8 }]] | ||
const item = arr.map((cur, index) => { | ||
return <div key={index.toString()} style={{ margin: '20px', backgroundColor: 'cyan' }}> | ||
{ | ||
cur.map((item, idx) => { | ||
return <p key={idx.toString()}>{item.a}</p> | ||
}) | ||
} | ||
</div> | ||
}) | ||
|
||
export const App = () => { | ||
const [btnText, setBtnText] = useState('Click me, please') | ||
const [state, dispatch] = useReducer(myReducer, { count: 0 }) | ||
|
||
function handleClick() { | ||
return setBtnText(btnText === 'Click me, please' ? 'Thanks, been clicked!' : 'Click me, please') | ||
} | ||
|
||
return <div> | ||
<button onClick={handleClick}>{btnText}</button> | ||
<div> | ||
<button onClick={() => dispatch({ type: 'countUp', count: state.count + 1 })}> | ||
+1 | ||
</button> | ||
<p>Count: {state.count}</p> | ||
</div> | ||
<div style={{ display: 'flex' }}> | ||
{item} | ||
</div> | ||
</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require('./index.css') | ||
require('./app.css') | ||
require('./index.less') | ||
require('./index.scss') | ||
import('./index.postcss') |