Created
February 27, 2021 22:13
-
-
Save kino6052/5888801da366af15c3ffb283f307a777 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 filterProducts = (event: IEvent, state: IState) => { | |
const value = event[2] || ""; | |
const filteredProducts = state.products | |
.filter(({ name }) => name.toLowerCase().includes(value.toLowerCase())) | |
.map(({ id }) => id); | |
return { | |
...state, | |
input: value, | |
productsToDisplay: filteredProducts | |
}; | |
}; | |
export const update = (event: IEvent, state: IState) => { | |
const isInputUpdated = | |
event[0] === "change" && | |
event[1] === "input-01" && | |
filterProducts(event, state); | |
return isInputUpdated || state; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment