Lifting up filter logic #846
-
We've implement a BUT To avoid repetitive code logic, we thought it might be better to only have one state e.g. As we're struggling quite some time now with the refactoring we're currently wondering if handling the filters centrally is even possible and if yes, we would need some hint how to do it. There is a test brand were you can check the current logic: https://github.com/SabinePfanner/plants-app/tree/test-sabine |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Here is a small prototype on how you could go for this feature: https://stackblitz.com/edit/vitejs-vite-um13ib?file=src%2FApp.jsx,src%2Fmain.jsx&terminal=dev In your current code I see one major issue: let filteredPlants;
filteredPlants = plants.filter(..);
filteredPlants = filteredPlants.filter(..);
filteredPlants = filteredPlants.filter(..); you should write it like this, without mutating a let: const filterForX = plants.filter(..);
const filterForY = filterForX.filter(..);
const filterForZ = filterForY.filter(..); Also in your multiselects you are declaring styled components inside another component, you should avoid declaring components in components |
Beta Was this translation helpful? Give feedback.
Here is a small prototype on how you could go for this feature:
https://stackblitz.com/edit/vitejs-vite-um13ib?file=src%2FApp.jsx,src%2Fmain.jsx&terminal=dev
In your current code I see one major issue:
you should write it like this, without mutating a let:
Also in your multiselects you are declaring styled components inside another component, you should avoid declaring components in components