Skip to content

Support for overriding prop values #530

Open
@elliotgeno

Description

@elliotgeno

Not sure if this functionality is already available, but currently, if you provide another component to an attribute, the JSX that is rendered shows the value of the object instead of the displayName. For example:
<Accordion.Toggle as={Card.Header} >
is rendered like:
<Accordion.Toggle as={{ $$typeof: Symbol(react.forward_ref), defaultProps: undefined, displayName: 'Card.Header', render: function noRefCheck() {} }} >

I would like to only show the displayName in this scenario.
Is there a way to override the string the attribute returns?

If not, maybe we can make a slight adjustment to options.filterProps to work similarly to options.displayName?
If you provide a function, and that function returns a string that isn't a boolean, use that new string for the attribute value instead.

Sound good?

Activity

elliotgeno

elliotgeno commented on Feb 14, 2020

@elliotgeno
Author

In this case my filterProps object would look like this:
filterProps: (value, key) => { if (key === "style") { return false } if (key === "as") { return value.displayName; } }

changed the title [-]Support for overriding attribute values for displayName...[/-] [+]Support for overriding prop values[/+] on Feb 14, 2020
dvnrsn

dvnrsn commented on Oct 19, 2020

@dvnrsn

This would be nice for really lengthy prop values as well. Say one has a long array of objects. It'd be nice to be able to render something like array or [{}, {}]

quantizor

quantizor commented on Nov 29, 2021

@quantizor

@Andarist would it be possible to add this functionality? maybe mapProps instead of filterProps so we're not overloading

Andarist

Andarist commented on Nov 29, 2021

@Andarist
Contributor

@probablyup note that I'm not a maintainer of this package - just fixed some issues here a few weeks back

as-zlynn-philipps

as-zlynn-philipps commented on Mar 4, 2022

@as-zlynn-philipps

Thanks for your work, @probablyup. I hope it gets merged. Although, it doesn't really address the need to format prop values on the fly as an escape hatch. I believe that would still be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @quantizor@elliotgeno@dvnrsn@Andarist@as-zlynn-philipps

        Issue actions

          Support for overriding prop values · Issue #530 · algolia/react-element-to-jsx-string