Hi,
I have a button that i am using to show more categories and show less categories. When a user clicks show more, the button state should switch and the button text should show less
. When a user clicks show less, extra categories should be hidden and the button text should read more
. The text updates fine, but i am having a hard time figuring out why the extra categories do not hide when i click show less. Any advise will be highly appreciated.
My state :
const [isActive, setIsActive] = useState(false);
My button and the extra components that should hide
<Card
className="card"
style={{ alignItems: "center", justifyContent: "center" }}
onClick={() => setIsActive(true)}
>
{isActive === true ? (
<Card.Content>
<Image
style={{
maxHeight: 200,
maxWidth: 200,
backgroundColor: "white"
}}
src={more}
wrapped
ui={false}
/>
<Card.Header style={{ textAlign: "center" }}>
Less Categories
</Card.Header>
</Card.Content>
) : (
<Card.Content>
<Image
style={{
maxHeight: 200,
maxWidth: 200,
backgroundColor: "white"
}}
src={more}
wrapped
ui={false}
/>
<Card.Header style={{ textAlign: "center" }}>
More Categories
</Card.Header>
</Card.Content>
)}
</Card>
{isActive === true && (
<div
xs={12}
sm={12}
md={12}
lg={12}
style={{ display: "flex", flexWrap: "wrap" }}
>
{categories !== ""
? categories.map((data, index) => {
let images = data.image;
if (data.main === "0") {
return (
<div className={classes.cardSection}>
<Card
className="card"
onClick={() => {
handleCat(data, data.id);
}}
>
<Card.Content>
<Card.Header>
{data.name}
</Card.Header>
</Card.Content>
</Card>
</div>
);
}
})
: null}
</div>
)}