Skip to content

Conversation

bschlenk
Copy link
Contributor

filterProps can now be passed as either an array of strings, or a function that will be called with the props value and key and return false to filter out that prop.

Closes #286

@armandabric
Copy link
Collaborator

Thanks for rebasing this PR 👍 I will have a look into it in the next days

@armandabric armandabric self-requested a review September 18, 2019 20:11
Copy link
Collaborator

@armandabric armandabric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this change ! Good idea to use a function here, it's a lot more powerful for the users 😃

Before we can merge we should also edit the Options flow definitions to allow add the functional version of the filterProps option:

filterProps: string[],

@leonelgalan
Copy link

Let's get this merged! I was looking for a way to filter props with value of undefined, having a function allows for this and more.

@armandabric
Copy link
Collaborator

Let's do this! 🚀

@armandabric armandabric merged commit c4908bb into algolia:master Jan 17, 2020
@armandabric
Copy link
Collaborator

Released in v14.3.0

@elliotgeno
Copy link

elliotgeno commented Feb 14, 2020

I see this is still relatively fresh!!
I would like to make one improvement... Instead of optionally showing the prop with a function, I would like to override the string for the prop's value with that the filterProps function.
For example, if you provide a prop with a reference to another Component, it will try to render that as an object.
Example:
<Accordion.Toggle as={Card.Header} >
returns this string:
<Accordion.Toggle as={{ $$typeof: Symbol(react.forward_ref), defaultProps: undefined, displayName: 'Card.Header', render: function noRefCheck() {} }} >

Ideally, I could write a function that replaces that prop value with the component's displayName. Similar to how options.displayName works... but for property values.

In the above example, I would like to pass the following to filterProps:
filterProps: (value, key) => { if (key === "style") { return false } if (key === "as") { return value.displayName; } }

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

Successfully merging this pull request may close these issues.

API request: filterFunction
4 participants