Skip to content

Commit 5004a32

Browse files
committed
typescript error duplicated
1 parent 41f1b4c commit 5004a32

28 files changed

Lines changed: 306 additions & 21 deletions

File tree

examples/00-example-basic/src/common/components/spinner/spinner.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,3 @@ export const Spinner = (props) => {
1515
);
1616
};
1717

18-
/*
19-
export const Spinner = () => {
20-
const { promiseInProgress } = usePromiseTracker();
21-
22-
return (
23-
<>
24-
promiseInProgress &&
25-
<div className="spinner">
26-
<Loader type="ThreeDots" color="#2BAD60" height="100" width="100" />
27-
</div>
28-
</>
29-
);
30-
};*/

examples/05-typescript/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
"webpack-dev-server": "^3.1.14"
3636
},
3737
"dependencies": {
38-
"react": "^16.8.2",
39-
"react-dom": "^16.8.2"
38+
"react": "^16.8.5",
39+
"react-dom": "^16.8.5",
40+
"react-loader-spinner": "^2.3.0",
41+
"react-promise-tracker": "file:../.."
4042
}
4143
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const fetchWithDelay = (url) => {
2+
const promise = new Promise((resolve, reject) => {
3+
setTimeout(() => {
4+
resolve(fetch(url, {
5+
method: 'GET',
6+
})
7+
.then((response) => response.json()));
8+
}, 3000)
9+
});
10+
11+
return promise;
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { fetchWithDelay } from './fetch';
2+
const url = 'https://jsonplaceholder.typicode.com/posts';
3+
4+
const fetchPosts = () => fetchWithDelay(url)
5+
.then((posts : any[]) => posts.slice(0, 10));
6+
7+
export const postAPI = {
8+
fetchPosts,
9+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { fetchWithDelay } from './fetch';
2+
const url = 'https://jsonplaceholder.typicode.com/users';
3+
4+
const fetchUsers = () => fetchWithDelay(url);
5+
6+
export const userAPI = {
7+
fetchUsers,
8+
};

examples/05-typescript/src/app.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.tables {
2+
display: flex;
3+
flex-direction: row;
4+
flex-wrap: nowrap;
5+
}
6+
7+
.tables > div {
8+
flex-basis: 50%;
9+
margin-left: 1rem;
10+
margin-right: 1rem;
11+
}

examples/05-typescript/src/app.tsx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import * as React from 'react';
2+
import { trackPromise } from 'react-promise-tracker';
3+
import { userAPI } from './api/userAPI';
4+
import { postAPI } from './api/postAPI';
5+
import { UserTable, PostTable, LoadButton } from './components';
6+
import './app.css';
7+
8+
interface State {
9+
users: any[],
10+
posts: any[],
11+
}
12+
13+
export class App extends React.Component<{}, State> {
14+
constructor(props) {
15+
super(props);
16+
17+
this.state = {
18+
users: [],
19+
posts: [],
20+
};
21+
22+
this.onLoadTables = this.onLoadTables.bind(this);
23+
}
24+
25+
onLoadTables() {
26+
this.setState({
27+
users: [],
28+
posts: [],
29+
});
30+
31+
trackPromise(
32+
userAPI.fetchUsers()
33+
.then((users : any[]) => {
34+
this.setState({
35+
users,
36+
})
37+
})
38+
);
39+
40+
trackPromise(
41+
postAPI.fetchPosts()
42+
.then((posts) => {
43+
this.setState({
44+
posts,
45+
})
46+
})
47+
);
48+
}
49+
50+
render() {
51+
return (
52+
<div>
53+
<LoadButton
54+
onLoad={this.onLoadTables}
55+
title="Load tables with delay"
56+
/>
57+
<div className="tables">
58+
<UserTable users={this.state.users} />
59+
<PostTable posts={this.state.posts} />
60+
</div>
61+
</div>
62+
);
63+
}
64+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './spinner';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.spinner {
2+
width: 100%;
3+
height: 100%;
4+
}
5+
6+
.spinner > div {
7+
display: flex;
8+
justify-content: center;
9+
align-items: center;
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from 'react';
2+
import { usePromiseTracker } from 'react-promise-tracker';
3+
import Loader from 'react-loader-spinner';
4+
import './spinner.css';
5+
6+
export const Spinner = (props) => {
7+
const { promiseInProgress } = usePromiseTracker(null);
8+
9+
return (
10+
promiseInProgress && (
11+
<div className="spinner">
12+
<Loader type="ThreeDots" color="#2BAD60" height="100" width="100" />
13+
</div>
14+
)
15+
);
16+
};

0 commit comments

Comments
 (0)