File tree 7 files changed +64
-50
lines changed
7 files changed +64
-50
lines changed Original file line number Diff line number Diff line change 19
19
work correctly both with client-side routing and a non-root public URL.
20
20
Learn how to configure a non-root public URL by running `npm run build`.
21
21
-->
22
- < title > React App </ title >
22
+ < title > Simple react json viewer </ title >
23
23
</ head >
24
24
< body >
25
25
< noscript > You need to enable JavaScript to run this app.</ noscript >
Original file line number Diff line number Diff line change 1
- .app {
2
- text-align : center;
3
- }
4
-
5
- .json-container {
6
- margin-left : 130px ;
7
- }
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import './App.css' ;
3
- import { Input } from './input/Input' ;
4
- import { Json } from "./json/Json" ;
3
+ import { JsonViewer } from "./json/JsonViewer" ;
5
4
6
5
7
6
export class App extends React . Component {
8
- constructor ( ) {
9
- super ( ) ;
10
- this . state = { json : { } } ;
11
- }
12
-
13
- dataLoaded = t => {
14
- this . setState ( ( ) => ( { json : t , error : false , loading : false } ) ) ;
15
- } ;
16
-
17
- onError = ( ) => {
18
- this . setState ( ( ) => ( { json : null , error : true , loading : false } ) ) ;
19
- } ;
20
-
21
- onLoading = ( ) => {
22
- this . setState ( ( ) => ( { loading : true } ) ) ;
23
- } ;
24
-
25
- renderData ( ) {
26
- if ( this . state . loading ) {
27
- return null ;
28
- }
29
-
30
- return this . state . error
31
- ? < div className = "error" > Error loading</ div >
32
- : < Json className = "json-container" json = { this . state . json } /> ;
33
- }
34
-
35
- renderLoader ( ) {
36
- if ( ! this . state . loading ) {
37
- return null ;
38
- }
39
- return < span > Loading....</ span > ;
40
- }
41
7
42
8
render ( ) {
43
9
return (
44
- < div className = "app" >
45
- < Input onDataLoaded = { this . dataLoaded } onError = { this . onError } onLoading = { this . onLoading } />
46
- { this . renderLoader ( ) }
47
- { this . renderData ( ) }
48
- </ div >
10
+ < JsonViewer />
49
11
) ;
50
12
}
13
+
51
14
}
52
15
53
16
export default App ;
Original file line number Diff line number Diff line change @@ -33,7 +33,6 @@ export class Input extends React.Component {
33
33
}
34
34
35
35
render ( ) {
36
- console . log ( styles ) ;
37
36
return (
38
37
< form className = { styles . form } onSubmit = { this . handleSubmit } >
39
38
< input className = { styles . input } type = "text" value = { this . state . value } onChange = { this . handleChange } />
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ export class Json extends React.Component {
28
28
const { folded} = this . state ;
29
29
30
30
const dotsClass = classnames ( { [ styles . folded ] : ! folded } ) ;
31
- console . log ( dotsClass ) ;
31
+
32
32
if ( ! json ) {
33
33
return null ;
34
34
}
Original file line number Diff line number Diff line change 38
38
.folded {
39
39
display : none;
40
40
}
41
+
42
+
43
+ .component {
44
+ text-align : center;
45
+ }
46
+
47
+ .container {
48
+ margin-left : 130px ;
49
+ }
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import styles from './Json.module.css' ;
3
+ import { Input } from "../input/Input" ;
4
+ import { Json } from "./Json" ;
5
+
6
+ export class JsonViewer extends React . Component {
7
+ constructor ( ) {
8
+ super ( ) ;
9
+ this . state = { json : { } } ;
10
+ }
11
+
12
+ dataLoaded = t => {
13
+ this . setState ( ( ) => ( { json : t , error : false , loading : false } ) ) ;
14
+ } ;
15
+
16
+ onError = ( ) => {
17
+ this . setState ( ( ) => ( { json : null , error : true , loading : false } ) ) ;
18
+ } ;
19
+
20
+ onLoading = ( ) => {
21
+ this . setState ( ( ) => ( { loading : true } ) ) ;
22
+ } ;
23
+
24
+ renderData ( ) {
25
+ if ( this . state . loading ) {
26
+ return null ;
27
+ }
28
+
29
+ return this . state . error
30
+ ? < div > Error loading</ div >
31
+ : < Json className = { styles . container } json = { this . state . json } /> ;
32
+ }
33
+
34
+ renderLoader ( ) {
35
+ if ( ! this . state . loading ) {
36
+ return null ;
37
+ }
38
+ return < span > Loading....</ span > ;
39
+ }
40
+
41
+ render ( ) {
42
+ return (
43
+ < div className = { styles . component } >
44
+ < Input onDataLoaded = { this . dataLoaded } onError = { this . onError } onLoading = { this . onLoading } />
45
+ { this . renderLoader ( ) }
46
+ { this . renderData ( ) }
47
+ </ div >
48
+ ) ;
49
+ }
50
+ }
You can’t perform that action at this time.
0 commit comments