Component with forwardRef passed as prop
See original GitHub issueconst A = () => <div />
const B = React.forwardRef(() => <div />)
What I get:
<Comp
a={A}
b={{
$$typeof: Symbol(react.forward_ref),
render: _c3
}}
/>
What I expect:
<Comp
a={A}
b={B}
/>
Repro: https://codesandbox.io/s/dank-cdn-ftvik?file=/src/App.js
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:11 (3 by maintainers)
Top Results From Across the Web
Forwarding Refs
Ref forwarding is an opt-in feature that lets some components take a ref they receive, and pass it further down (in other words,...
Read more >React forwardRef: ref and other props
The order is irrelevant. forwardRef extracts the ref prop from the properties and creates a wrapper. The other props are available in props...
Read more >How to use React's forwardRef function
Our task is to forward the ref that the Input component receives to the HTML input element. We do that by wrapping the...
Read more >React: All you need to know about Ref Forwarding
React.forwardRef takes a function with props and ref arguments. This function returns a JSX Element. ... The props hold the props of the...
Read more >Forwarding refs to components | by Mario Kandut
In React ref and key are handled differently. · The React.forwardRef API receives props and ref parameters and returns a React.node . ·...
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
OTOH - this really could be handled in the same way for any prop. People probably rarely want to see the react element’s internal structure in their stringified trees
Agreed.
function noRefCheck() {}
isn’t useful either. Nor is() => {}
when it should be the element type (Comp
).Here, I’d expect
onClick
to be() => {}
but maybe that’s a Storybook actions issue.EDIT: Okay, so I figured out how to configure the options for this package in Storybook via global
parameters.jsx
.I can set
showFunctions
totrue
there, but then I run into the problem that this issue #613 is really about. Instead of the component name, it’s gobbledegook. And, since in my case, the function name is a bit different from the exported module name, that adds a layer of complexity. In my case, I might be able to leveragefunctionValue
to achieve the desired result.The reason
onClick
was showingfunction noRefCheck() {}
is because my story uses Controls, so I’m setting theicon
prop dynamically in the UI. SincesortProps
istrue
by default, it looks like the fallback value foricon
was being assigned toonClick
I think? Maybe? Due to this bit in the README?Either way, explicitly setting
sortProps
tofalse
yields a more expected result:Just reporting my findings. ✌️
EDIT 2:
With the following config:
Voila:
Although, it’s kinda jank because that
functionValue
would apply to any function prop. It would be neat if the prop name were passed as well, that way you could modifyfunctionValue
conditionally based on the component prop. Even better, apropValue
function that takes in the prop key/value and allows you to customize the output. Related: #278, #530, #682