Skip to content

Instantly share code, notes, and snippets.

@chestozo
Last active May 15, 2020 16:13
Show Gist options
  • Save chestozo/72ae44152b1374064d2038e6579d57fa to your computer and use it in GitHub Desktop.
Save chestozo/72ae44152b1374064d2038e6579d57fa to your computer and use it in GitHub Desktop.
Quick print props for component component =) Useful for Formik
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