Skip to content

feat: add useEffect base #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ Learn React with TypeScript
- State(withStateHandlers)
- [Base](https://github.com/locol23/learn-react-typescript/tree/master/packages/recompose-state-base)
- React Hooks
- State(useState)
- Counter(useState, useEffect, useCallback)
- [Base](https://github.com/locol23/learn-react-typescript/tree/master/packages/hooks-state-base)
- [Goal](https://github.com/locol23/learn-react-typescript/tree/master/packages/hooks-state-goal)
- useEffect
- [Base](./packages/hooks-use-effect-base)
- State(useReducer)
- React + Redux
- [Base](https://github.com/locol23/learn-react-typescript/tree/master/packages/redux-base)
Expand Down
4 changes: 4 additions & 0 deletions packages/hooks-use-effect-base/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["react", ["env", {"targets": {"chorme": 67} }]],
"plugins": ["transform-object-rest-spread", "transform-class-properties"]
}
18 changes: 18 additions & 0 deletions packages/hooks-use-effect-base/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# hooks-use-effect-base

[Hooks API Reference](https://reactjs.org/docs/hooks-reference.html)

## useEffect

```tsx
const App = () => {
const [title, setTitle] = useState('Initial Title')

useEffect(() => {
setTitle('Use Effect')
}, [])

return <h1>{title}</h1>
}
```

7,847 changes: 7,847 additions & 0 deletions packages/hooks-use-effect-base/package-lock.json

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions packages/hooks-use-effect-base/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "hooks-use-effect-base",
"version": "1.0.0",
"main": "index.js",
"repository": "https://github.com/locol23/learn-react-ts.git",
"license": "MIT",
"scripts": {
"clean": "rimraf dist",
"parcel:dev": "parcel src/index.html",
"parcel:prod": "parcel build src/index.html",
"dev": "run-s clean parcel:dev",
"build": "run-s clean parcel:prod"
},
"dependencies": {
"react": "^16.12.0",
"react-dom": "^16.12.0"
},
"devDependencies": {
"@types/react": "^16.9.17",
"@types/react-dom": "^16.9.4",
"babel-core": "^6.26.3",
"npm-run-all": "^4.1.5",
"parcel-bundler": "^1.12.4",
"rimraf": "^3.0.0"
}
}
26 changes: 26 additions & 0 deletions packages/hooks-use-effect-base/src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { useEffect, useState } from 'react'

export const App = () => {
const [title, setTitle] = useState('Initial Title')

useEffect(() => {
setTimeout(() => {
setTitle('Use Effect')
}, 2000)
}, [])

const [text, setText] = useState('Initial Text')
const handler = () => setText('Text 1')
const handler2 = () => setText('Text 2')

useEffect(() => console.log(`current text is ${text}`), [text])

return (
<>
<h1>{title}</h1>
<button onClick={handler}>click1</button>
<button onClick={handler2}>click2</button>
</>
)
}

11 changes: 11 additions & 0 deletions packages/hooks-use-effect-base/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>React Typescript Boilerplate</title>
</head>
<body>
<div id="app">Loading...</div>
<script src="index.tsx"></script>
</body>
</html>
5 changes: 5 additions & 0 deletions packages/hooks-use-effect-base/src/index.tsx
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 './components/App'

ReactDOM.render(<App />, document.getElementById('app'))
20 changes: 20 additions & 0 deletions packages/hooks-use-effect-base/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "esnext",
"module": "ES2015",
"allowJs": false,
"jsx": "react",
"sourceMap": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"alwaysStrict": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"strictPropertyInitialization": true,
"rootDir": "src",
"outDir": "./dist/"
},
"exclude": ["dist", "node_modules"]
}