Crafting a Generic Filter Function
Explore how to develop a generic filter function in TypeScript and create dynamic React components to apply flexible filtering. Understand handling edge cases like empty strings, null, and undefined values by leveraging JavaScript's boolean coercion and array methods for effective data filtering.
We'll cover the following...
It’s time to create the final generic functionality in this course—generic filtering. Filtering is like searching in that we’ll utilize JavaScript’s built-in filter function, but our predicate function will be more complex.
Filtering vs. Searching and Sorting
In some ways, filtering isn’t as intuitive as search or sort. For example, let’s consider a property that is of type string. There are numerous edge cases we have to consider. For example, what do we do with properties that have any empty string value, like ""? What do we do if the value is null? What if it’s undefined?
There are a few options available to us. We could remove these empty null ...