Skip to content

Instantly share code, notes, and snippets.

@kino6052
Last active February 28, 2021 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kino6052/f9502780cac2dd721813558fccd7dbc6 to your computer and use it in GitHub Desktop.
Save kino6052/f9502780cac2dd721813558fccd7dbc6 to your computer and use it in GitHub Desktop.
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