Skip to content

Instantly share code, notes, and snippets.

@kino6052
Created February 27, 2021 22:13
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/5888801da366af15c3ffb283f307a777 to your computer and use it in GitHub Desktop.
Save kino6052/5888801da366af15c3ffb283f307a777 to your computer and use it in GitHub Desktop.
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