@@ -11,29 +11,32 @@ interface Props {
11
11
const JSONView = ( props : Props ) => {
12
12
const { value, command = '' } = props
13
13
14
- const [ formattedValue , setFormattedValue ] = useState ( '' )
14
+ const [ result , setResult ] = useState < any > ( null )
15
15
16
16
useEffect ( ( ) => {
17
- try {
18
- JSONBigInt ( { useNativeBigInt : true } ) . parse ( value )
19
- } catch ( _err ) {
20
- const formatResponse = async ( ) => {
21
- const formattedResponse = await formatRedisReply ( value , command )
22
- setFormattedValue ( formattedResponse )
17
+ const parseJSON = async ( value : string , command : string ) => {
18
+ try {
19
+ const json = JSONBigInt ( { useNativeBigInt : true } ) . parse ( value )
20
+ setResult ( { value : json , isValid : true } )
21
+ } catch ( _err ) {
22
+ const reply = await formatRedisReply ( value , command )
23
+ setResult ( { value : reply , isValid : false } )
23
24
}
24
- formatResponse ( )
25
25
}
26
- } , [ ] )
26
+
27
+ parseJSON ( value , command )
28
+ } , [ value ] )
29
+
30
+ if ( ! result ) return null
27
31
28
32
return (
29
33
< >
30
- { formattedValue && (
31
- < div className = "cli-output-response-success" > { formattedValue } </ div >
32
- ) }
33
- { ! formattedValue && (
34
+ { result . isValid ? (
34
35
< div className = "jsonViewer" data-testid = "json-view" >
35
- < JsonPretty data = { JSONBigInt ( { useNativeBigInt : true } ) . parse ( value ) } space = { 2 } />
36
+ < JsonPretty data = { result . value } space = { 2 } />
36
37
</ div >
38
+ ) : (
39
+ < div className = "cli-output-response-success" > { result . value } </ div >
37
40
) }
38
41
</ >
39
42
)
0 commit comments