admin管理员组

文章数量:1429155

I work with Carousel view, and i have some dynamicaly elements, which should appear from Json list.

{
        category: "Category",
        code: "421313",
        title: "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
        price: 156,
        sold: false,
        salePrice: false
      },

As u can see i have two boolean value, and if thi value true i need to show some div element on the view.

               <div className={classes.card_ceromented}>
                Remended
                </div>
              <div className={classes.card_top_product}>
                Top Product
                </div>

classes.card_top_product this element i need to show hide on bollean value.

How i can show div element on true json value?

My code: JsFiddle

I work with Carousel view, and i have some dynamicaly elements, which should appear from Json list.

{
        category: "Category",
        code: "421313",
        title: "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
        price: 156,
        sold: false,
        salePrice: false
      },

As u can see i have two boolean value, and if thi value true i need to show some div element on the view.

               <div className={classes.card_ceromented}>
                Remended
                </div>
              <div className={classes.card_top_product}>
                Top Product
                </div>

classes.card_top_product this element i need to show hide on bollean value.

How i can show div element on true json value?

My code: JsFiddle

Share Improve this question asked May 25, 2021 at 11:10 AndrewAndrew 6221 gold badge6 silver badges31 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 15

You can do conditional rendering .

{ category.sold && (<div> This gets rendered when sold is true</div>)}

Conditional Rendering In React

本文标签: javascriptHow to showhide elements on boolean value on reactjsStack Overflow