2
I’m trying to come up with a logic of a toggle, which activates/disables a kind of filter, but now I need to implement a new functionality in it, it works like this, if I click on a category button, it makes a request, switches to on (which causes some items to be rendered in my other component, step via context api), if I click dnv, it switches to off and the rendering goes back to what it was before, the problem is, I need to implement it to work with more than one category button, that is, if I click on a category (it stays on) and click on another category (it changes to off), which actually should not occur.
function toggleFunc(serviceEndpoint, category) {
onClickCategoryFetch(serviceEndpoint, category);
setToggle((prevToggle) => !prevToggle);
}
return Object.values(typeCategory)
.slice(0, FIRST_FIVE_CATEGORY)
.map((category) => (
<button
type="button"
key={ `${category.strCategory}` }
data-testid={ `${category.strCategory}-category-filter` }
onClick={ () => toggleFunc(endpoint, category.strCategory) }
>
{category.strCategory}
</button>
));
}
Thank you so much for the help, I liked the abstraction, can solve in a very good way!
– Arthur Nunes