Skip to content

Instantly share code, notes, and snippets.

@pushkar100
Created May 2, 2022 07:45
Show Gist options
  • Save pushkar100/9a9e94f18076aef417c2d77c568627d2 to your computer and use it in GitHub Desktop.
Save pushkar100/9a9e94f18076aef417c2d77c568627d2 to your computer and use it in GitHub Desktop.
<ProductSearchFilter
products={["t-shirt", "shorts", "jeans"]}
colors={["red", "white", "black"]}
onSearch={(...args) => console.log(args)}
reducer={(state, action) => {
// 1. Run the default reducer:
const newState = productSearchFilterReducer(state, action);
// 2. Override its behaviour to fit your needs as a consumer:
if (
newState.product === "t-shirt" &&
newState.colors.includes("black")
) {
newState.colors.push("midnight blue");
} else {
newState.colors = newState.colors.filter(
(c) => c !== "midnight blue"
);
}
// 3. Return updated state:
return newState;
}}
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment