1

I'm trying to dynamically add PivotItems to a Fabric UI Pivot.

return (
    <div>
         <PrimaryButton style={{margin:5 }} onClick={addItem}>
            Add
        </PrimaryButton>
        <Pivot aria-label="My Items">
         
        {items.map((item)=>{
            
            return (
            <div key={uniqueId}>
                <PivotItem headerText="test">
                    Test
                </PivotItem>     
            </div>)
        })}
        </Pivot>
    </div>
)

but the items are not rendering. When I remove all the Pivot/item-stuff and just print out some text it works fine...

Tobias Koller
  • 2,116
  • 4
  • 26
  • 46

1 Answers1

0

ok I finally found the issue here. Inside the map-function I used

<div key...

but this code is inside a <pivot> which allows only <PivotItem> as childs...

so I fixed it like this and it works:

return (
<div>
     <PrimaryButton style={{margin:5 }} onClick={addItem}>
        Add
    </PrimaryButton>
    <Pivot aria-label="My Items">
     
    {items.map((item)=>{
        
        return (           
            <PivotItem headerText="test" key={uniqueId}>
                Test
            </PivotItem>     
       )
    })}
    </Pivot>
</div>

)

Tobias Koller
  • 2,116
  • 4
  • 26
  • 46