A
A
AlexKindGeek2018-09-24 18:08:51
React
AlexKindGeek, 2018-09-24 18:08:51

How can you simplify the rendering of a component?

Hello. I make tabs through material ui and I don’t really like this thing:

{value === 0 && <TabContainer>Item One</TabContainer>}
{value === 1 && <TabContainer>Item Two</TabContainer>}
{value === 2 && <TabContainer>Item Three</TabContainer>}
{value === 3 && <TabContainer>Item Four</TabContainer>}
{value === 4 && <TabContainer>Item Five</TabContainer>}
{value === 5 && <TabContainer>Item Six</TabContainer>}
{value === 6 && <TabContainer>Item Seven</TabContainer>}

How can this be avoided (simplified)?
EXAMPLE

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-09-24
@AlexKindGeek

Put an array in state:
And in render it will become like this:
UPD. And if you add icons to the array, then the rendering of Tabs will also be simplified .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question