Created
May 2, 2022 07:45
-
-
Save pushkar100/9a9e94f18076aef417c2d77c568627d2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<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