Created
November 17, 2020 20:27
-
-
Save gaurangrshah/1e21220123ab11bb81f6fe6d7751e34c to your computer and use it in GitHub Desktop.
#chakra-ui #json #data #handling #view #viewer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react'; | |
import { Box, Button, Code } from '@chakra-ui/core'; | |
const json = ({ data }) => { | |
const [open, setOpen] = useState(false); | |
React.useEffect(() => { | |
setOpen(data ? true : false); | |
}, [data]); | |
return ( | |
open && ( | |
<Box position="absolute" top="2em" right="1em" bg="blue" border="1px sold red"> | |
<Button top="10px" left="10px" onClick={() => setOpen(false)}> | |
X | |
</Button> | |
<Code>{JSON.stringify(data, null, 2)}</Code> | |
</Box> | |
) | |
); | |
}; | |
export default json; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment