Last active
February 28, 2021 19:11
-
-
Save kino6052/f9502780cac2dd721813558fccd7dbc6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const reduce = ( | |
event: IEvent, | |
state: typeof initialState | |
): typeof initialState => { | |
if (event[0] === "change" && event[1] === "input-01") { | |
const value = event[2]; | |
const filteredProducts = state.products | |
.filter(({ name }) => name.toLowerCase().includes(value.toLowerCase())) | |
.map(({ id }) => id); | |
return { | |
...state, | |
input: value, | |
productsToDisplay: filteredProducts, | |
}; | |
} else { | |
return state; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment