-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Component with forwardRef passed as prop #613
Comments
Thanks to #617 we are now supporting it('should use inferred function name as display name for `forwardRef` element when used in a props', () => {
const Comp = () => <div />;
const A = () => <div />;
const B = React.forwardRef(function B(_props, ref) {
return <div ref={ref} />;
});
expect(reactElementToJSXString(<Comp a={A} b={B}></Comp>)).toEqual(
`<Comp
a={function noRefCheck() {}}
// Should be <B />
b={{
$$typeof: Symbol(react.forward_ref),
render: function noRefCheck() {}
}}
/>`
);
}); As it's fresh in it's mind maybe @Andarist have an idea? |
It's an interesting case - this is not a valid React element so it doesn't go into this logic: react-element-to-jsx-string/src/formatter/formatPropValue.js Lines 47 to 54 in 2c5132e
A valid React element is a result of the |
Good point. I'm not sure what we could propose as in fact |
Well, it could still be formatted somehow - since we can recognize that it's not "just an object". But I don't believe printing I probably won't take this work on myself though - it shouldn't be overly hard though with the groundwork being laid out already. |
I agree with you we could easily add a dedicated render for this use case but I lack of idea on the shape of this render. If people really need this they could explain us their use case and make us proposal. If it's a reasonable use case we will consider to handle this. I keep this issue open for the discussion. |
My exact use case is documenting polymorphic components with <Link as={RouterLink}>Link</Link> If the |
I see. We could maybe have a dedicated behavior for the |
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 |
I think we have two cases here to handle:
The first case can be solved like this:
Or we can export Regarding function components, what about this method? Could also improve regular functions display by using the
@armandabric @Andarist WDYT? |
Is there a PR for this? I don't see one linked. |
Agreed. Here, I'd expect EDIT: Okay, so I figured out how to configure the options for this package in Storybook via global export const parameters = {
jsx: {
showFunctions: true,
// ...
}
} I can set The reason
Either way, explicitly setting Just reporting my findings. ✌️ EDIT 2: With the following config: BasicUsage.parameters = {
jsx: {
filterProps: ['onClick'],
functionValue: (fn: any) => fn.name.replace('Svg', ''),
showFunctions: true,
},
} Voila: Although, it's kinda jank because that |
What I get:
What I expect:
Repro: https://codesandbox.io/s/dank-cdn-ftvik?file=/src/App.js
The text was updated successfully, but these errors were encountered: