Answer the question
In order to leave comments, you need to log in
Do I need to duplicate passing props in the parent component?
There is a Tabs component (accepts 4 props).
Which displays multiple Tab components (accepts 5 props).
In turn, the Tab component has a Tooltip component (accepts 3 props).
I'm creating a separate component for the UsersTabs page
that encapsulates the data and renders the Tabs.
Vporos.
Should the UsersTabs component accept all those properties that are accepted by Tooltip, Tab, Tabs? (12 props) or am I doing something wrong?
Is it normal (good?) to pass 1 prop as an array of objects with all the properties of internal components and scatter them inside UsersTabs?
for example
tabs={
[
{
'tabName': 'tab1',
'tooltipText': 'this is tab1',
'onTabClick': () => func(),
},
{
'tabName': 'tab2',
'tooltipText': 'this is tab2',
'onTabClick': () => func(),
}
]}
Answer the question
In order to leave comments, you need to log in
I'll try to help you. If you have few tabs, then in order not to fence 12 props, you can use this approach:
const UserTabs = () => (
<Tabs>
<Tab
name={name}
tooltipText={tooltipText}
onTabClick={onTabClick}
/>
<Tab
name={name}
tooltipText={tooltipText}
onTabClick={onTabClick}
/>
</Tabs>
);
UserTabs
and try to solve the problem through composition. tabs
using iteration ):Tabs
UserTabs
const createTabs = (tab) => tabs.map((tab) => {
<Tab
name={tab.name}
tooltipText={tab.tooltipText}
onTabClick={tab.onTabClick}
/>
});
const UserTabs = ({ tabs }) => <Tabs tabs={createTabs(tabs)} />;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question