Last active
May 15, 2020 16:13
-
-
Save chestozo/72ae44152b1374064d2038e6579d57fa to your computer and use it in GitHub Desktop.
Quick print props for component component =) Useful for Formik
This file contains 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 from 'react' | |
import styled from 'styled-components' | |
import { Box, TextBox } from 'ui-kit' | |
const Wrapper = styled(Box)` | |
position: fixed; | |
top: 0; | |
right: 0; | |
overflow: auto; | |
font-size: 80%; | |
z-index: 9999; | |
` | |
export const ShowProps = ({ | |
props, | |
transformData = (data) => data, | |
}: { | |
props: object | |
transformData: (data: object) => object | |
}) => { | |
let output | |
try { | |
output = JSON.stringify(transformData(props), null, 2) | |
} catch (ex) { | |
output = `ERROR: ${ex.message} ${ex.stacktrace}` | |
} | |
return ( | |
<Wrapper use='pre' width='25vw' maxHeight='100vh'> | |
<TextBox bg='grey-100' color='grey-35' variant='caption' p={1}> | |
{output} | |
</TextBox> | |
</Wrapper> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment