Skip to content

Instantly share code, notes, and snippets.

@gaurangrshah
Created November 17, 2020 20:27
Show Gist options
  • Save gaurangrshah/1e21220123ab11bb81f6fe6d7751e34c to your computer and use it in GitHub Desktop.
Save gaurangrshah/1e21220123ab11bb81f6fe6d7751e34c to your computer and use it in GitHub Desktop.
#chakra-ui #json #data #handling #view #viewer
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