Note: We want to show all blogposts if the search is empty (e.target.value === "")
This will work but there are some flaws with this approach:
If blogposts changes, we'll need to make sure that the filtered list is updated
If we want to persist the search parameter across pages (e.g. using a query parameter) we'll need to make sure the filtered list is initialised correctly
The component is hard to reason about
We'll have to make sure filtered is always up-to-date.
This becomes a lot harder with bigger components.
How can we fix this?
In this case we can calculate the filtered list if we have blogposts and search: