|
1 | | -// import React from 'react' |
2 | | -// // import FakerComponents from './examples/components/Faker' |
3 | | -// // import JsonPlaceHolderComponents from './examples/components/JsonPlaceHolder' |
4 | | -// // import DummyComponents from './examples/components/Dummy' |
5 | | -// // import UIFacesComponents from './examples/components/UIFaces' |
6 | | -// // import { useStarWars } from './development/hooks/StarWars' |
7 | | -// import { useStarWars } from 'react-fakers' |
8 | | - |
9 | | -// const App = () => { |
10 | | -// const { success, error, loading } = useStarWars() |
11 | | -// if (error) { |
12 | | -// console.log(error.message) |
13 | | -// } |
14 | | - |
15 | | -// return ( |
16 | | -// <> |
17 | | -// {!loading && <h4>Loading....</h4>} |
18 | | -// <ul>{loading && success.map((val, id) => <li key={id}>{val.name}</li>)}</ul> |
19 | | -// </> |
20 | | -// ) |
21 | | -// } |
22 | | - |
23 | | -// export default App |
24 | | - |
25 | | -import React, { Component } from 'react' |
26 | | -import { Faker } from 'react-fakers' |
27 | | - |
28 | | -class App extends Component { |
29 | | - constructor(props) { |
30 | | - super(props) |
31 | | - this.state = { |
32 | | - loading: false, |
33 | | - data: [] |
34 | | - } |
| 1 | +import React from 'react' |
| 2 | +import { useStarWars } from 'react-fakers' |
| 3 | +// import FakerComponents from './examples/components/Faker' |
| 4 | +// import JsonPlaceHolderComponents from './examples/components/JsonPlaceHolder' |
| 5 | +// import DummyComponents from './examples/components/Dummy' |
| 6 | +// import UIFacesComponents from './examples/components/UIFaces' |
| 7 | +// import { useStarWars } from './development/hooks/StarWars' |
| 8 | + |
| 9 | +const App = () => { |
| 10 | + const { success, error, loading } = useStarWars() |
| 11 | + if (error) { |
| 12 | + console.log(error.message) |
35 | 13 | } |
36 | 14 |
|
37 | | - onSuccess = (res) => { |
38 | | - this.setState({ |
39 | | - loading: true, |
40 | | - data: res |
41 | | - }) |
42 | | - } |
43 | | - |
44 | | - onError = (error) => { |
45 | | - if (error) { |
46 | | - alert(error.message) |
47 | | - } |
48 | | - } |
49 | | - |
50 | | - render() { |
51 | | - return ( |
52 | | - <> |
53 | | - <Faker success={this.onSuccess} error={this.onError} /> |
54 | | - |
55 | | - {!this.state.loading && <h4>Loading....</h4>} |
56 | | - <ul> |
57 | | - {this.state.loading && |
58 | | - this.state.data.map((val, id) => ( |
59 | | - <li key={val.uuid}> |
60 | | - {val.firstname} {val.lastname} - {val.email} |
61 | | - </li> |
62 | | - ))} |
63 | | - </ul> |
64 | | - </> |
65 | | - ) |
66 | | - } |
| 15 | + return ( |
| 16 | + <> |
| 17 | + {!loading && <h4>Loading....</h4>} |
| 18 | + <ul>{loading && success.map((val, id) => <li key={id}>{val.name}</li>)}</ul> |
| 19 | + </> |
| 20 | + ) |
67 | 21 | } |
68 | 22 |
|
69 | 23 | export default App |
0 commit comments