PropsTable is not working with components encapsulated by React.forwardRef()
See original GitHub issue<PropsTable of={Input} />
only works when I remove the React.forwardRef()
. The following code is Typescript, and I also have typescript: true
on my config.
import * as React from "react"
import styled from "styled-components"
// Estilos ---------------------------------------------------------------------
const StyledInput = styled.input.attrs({
className: "form-control",
})`
height: 40px;
margin-bottom: 0;
font-size: 0.8125rem;
`
const FormRow = styled.div.attrs({
className: "form-group",
})`
margin-bottom: 1.25rem;
`
// <Input /> -------------------------------------------------------------------
interface IPInput {
id: string
label?: string | false
placeholder?: string
}
const Input = React.forwardRef(
(
{ id, label, placeholder, ...extraProps }: IPInput,
ref: React.RefObject<HTMLInputElement>,
) => (
<FormRow>
<label
htmlFor={id}
className={[false === label ? "sr-only" : ""].join(" ")}
>
{false === label && placeholder ? placeholder : label}
</label>
<StyledInput
innerRef={ref}
id={id}
placeholder={placeholder}
{...extraProps}
/>
</FormRow>
),
)
export default Input
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:9 (3 by maintainers)
Top Results From Across the Web
PropsTable is not working with components encapsulated by ...
only works when I remove the React.forwardRef(). The following code is Typescript, and I also have typescript: true on my config. import ...
Read more >Forwarding Refs - React
Regular function or class components don't receive the ref argument, and ref is not available in props either. Ref forwarding is not limited...
Read more >React - sending down ref as a prop not working - Stack Overflow
Working example with ref renamed to parentRef in both components. ... forwardRef to pass refs in the component hierarchy.
Read more >Everything You Need to Know About Refs in React
Short for “reference”, refs are a way to access underlying DOM elements in a React component. There are many reasons why you would...
Read more >Forwarding refs to components - Mario Kandut
forwardRef API receives props and ref parameters and returns a React.node . In HOC, it's important to know that ref is not a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think that this will be fixed in the v1 ✌️
Hi
PropsTable uses
__docgenInfo
’s data. you do not have access to it in a HOC but in the wrapped component. You have to give the wrapped component to<PropsTable>
2 solutions :
<PropsTable>
render().type
to access to wrapped component via hocBy default
MyComponent.render().type
does not have__docgenInfo
.__docgenInfo
is generated by babel-plugin-react-docgen and the default value of theresolver
option (findAllExportedComponentDefinition
) doesn’t create the__docgenInfo
if the component is not exported. You should usefindAllComponentDefinitions
value. See https://github.com/storybooks/babel-plugin-react-docgen#babelrc-options for more info.Otherwise you should export the wrapped component (like in the first solution) to have access to
__docgenInfo
.