Docz: <PropsTable> wont render when using HOC component

Created on 14 Feb 2019  路  2Comments  路  Source: doczjs/docz

Bug Report

Describe the bug

I have a basic React + styled-components setup. Everything is working great until I use the withTheme HOC from styled-components. If I use any HOC's in my components the <PropsTable> no longer renders... Is there a solution to this?

To Reproduce

Docz versions:
docz v0.13.7
docz-theme-default v0.13.7

(I also tried with 0.14.0-alpha.68 on both but still doesn't work..

This is my component file Test.js

import React from 'react'
import PropTypes from 'prop-types'
import styled, { withTheme } from 'styled-components'

const Test = ({ name }) => (
  <Name>{name}</Name>
)

const Name = styled.div`
  display: inline-flex;
  padding: 15px 20px;
  margin: 10px;
  border-radius: 5px;
  background-color: yellowgreen;
  justify-content: center;
  align-items: center;
  color: white;
`
Test.propTypes = {
  name: PropTypes.string
}

Test.defaultProps = {
  name: 'John Deere'
}

export default withTheme(Test)

and my Test.mdx file

name: Test
menu: Components
---

import { Playground, PropsTable } from 'docz'
import Test from './'

# Test

<PropsTable of={Test} />

## Basic Usage

<Playground>
  <Test />
  <Test name="Jackson" />
</Playground>

Expected behavior
The props table should render like below:
(this only renders when I export the component without the HOC: export default Test)

screen shot 2019-02-14 at 3 17 59 pm

Any kind of fix with using HOC's would be helpful...

Most helpful comment

This is a huge problem when wrapping components in React.memo.

All 2 comments

There is a bug with the same issue with forwardRef : https://github.com/pedronauck/docz/issues/334#issuecomment-457510992

You have to use Test component to use <PropsTable>.

  • You can import Test and withTheme(Test). WithTheme(Test) would be the default export.
import Test, {Test as TestWithPropTypes} from './'
<Playground><Test /></Playground>
<PropsTable of={TestWithPropTypes} />
  • the other solution is to access to Test with render.type() :
<PropsTable of={Test.render().type} />

This is a huge problem when wrapping components in React.memo.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mariusespejo picture mariusespejo  路  3Comments

capaj picture capaj  路  3Comments

wldcordeiro picture wldcordeiro  路  3Comments

nicholasess picture nicholasess  路  3Comments

koddr picture koddr  路  3Comments