Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

69
Views
Dynamically add values to specific property in object - Fluent UI React ContextualMenu

I have the following ContextualMenu structure inside my SPFx Extension build with Fluent UI React:

const menuProps: IContextualMenuProps = {
  items: [
    {
      key: 'Access',
      itemType: ContextualMenuItemType.Section,
      sectionProps: {
        topDivider: true,
        bottomDivider: true,
        title: 'Sites you have access to',
        items: [
          { key: 'DynamicValue1.1', text: 'DynamicValue1.2' },
          { key: 'DynamicValue2.1', text: 'DynamicValue2.2' },
        ],
      },
    },
  ],
};

I also a MS Graph call running getting me some SharePoint Sites & Teams.

I would now like to push those dynamic responses to the to the menuProps at the right place.

So basically add the dynamic array into the nested items object.

items: [
          { key: 'DynamicValue1.1', text: 'DynamicValue1.2' },
          { key: 'DynamicValue2.1', text: 'DynamicValue2.2' },
        ],

How can I target that "object"? (hope I understand correctly and items is an object...)

Is there a wait to do this using array.push()?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To make this library agnostic, it would look something like this:

 const obj = {
  items: [
    {
      key: 'Access',
      itemType: '',
      sectionProps: {
        topDivider: true,
        bottomDivider: true,
        title: 'Sites you have access to',
        items: [
          { key: 'DynamicValue1.1', text: 'DynamicValue1.2' },
          { key: 'DynamicValue2.1', text: 'DynamicValue2.2' },
        ],
      },
    },
  ],
};


obj.items[0].sectionProps.items.push({ key: 'DynamicValue3.1', text: 'DynamicValue3.2' })

console.log(obj.items[0].sectionProps.items)

Your console.log would return this:

[
  { key: 'DynamicValue1.1', text: 'DynamicValue1.2' },
  { key: 'DynamicValue2.1', text: 'DynamicValue2.2' },
  { key: 'DynamicValue3.1', text: 'DynamicValue3.2' }
]

If you can access menuProps: IContextualMenuProps, then just replace obj with the necessary variable.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!