Adding dynamic items with content reuse in React Tab component (2024)

    29 Aug 202312 minutes to read

    You can add dynamic tabs by reusing the content using React template. Tabs can be added dynamically by passing array of items and index value to the addTab method.

    Content reuse can be achieved by using the following steps:

    1. Declare a template within the function returns jsx element. If the template does not need arguments no need to pass the properties.
    2. Assign the function as value for the template property.
    3. Provide separate template declaration for each react component and pass content by dynamically adding tab. It will reuse the content of react component.

    Refer to the following sample.

    import { useRef } from 'react';import * as React from "react";import * as ReactDOM from 'react-dom/client';import { TabComponent, TabItemDirective, TabItemsDirective } from '@syncfusion/ej2-react-navigations';import { DatePickerComponent } from '@syncfusion/ej2-react-calendars';import { DropDownListComponent } from '@syncfusion/ej2-react-dropdowns';const App = () => { const tabObj = useRef(null); const Dropdown = (props) => { return ( <div> <DropDownListComponent dataSource={props.data} placeholder="Select a game" /> </div> ); } const addButtonClicked = (e) => { const newTabItem = [ { header: { text: 'DynamicTabItem' }, content: thirdDropdownTemplate } ]; tabObj.current.addTab(newTabItem, 1); } const removeButtonClicked = (e) => { tabObj.current.removeTab(1); } const firstDropdownTemplate = () => { let sportsData = [ 'Badminton', 'Basketball', 'Cricket', 'Golf', 'Hockey', 'Rugby' ]; return <Dropdown data={sportsData} />; } const secondDropdownTemplate = () => { let sportsData = [ 'Cricket', 'Golf', 'Hockey', 'Rugby', 'Badminton', 'Basketball' ]; return <Dropdown data={sportsData} />; } const thirdDropdownTemplate = () => { let sportsData = [ 'Rugby', 'Badminton', 'Basketball', 'Cricket', 'Golf', 'Hockey' ]; return <Dropdown data={sportsData} />; } const datePickerTemplate = () => { return ( <div> <DatePickerComponent /> </div> ); } let tabItemsHeaderText = [ { text: 'DatePicker' }, { text: 'Dropdown' }, { text: 'Reused Dropdown' } ]; return ( <div id='container'> <button id="add" className="e-btn" onClick={addButtonClicked} > Click to add </button> <button id="remove" className="e-btn" onClick={removeButtonClicked} > Click to remove </button> <TabComponent id="tabElement" ref={tabObj} > <TabItemsDirective> <TabItemDirective header={tabItemsHeaderText[0]} content={datePickerTemplate} /> <TabItemDirective header={tabItemsHeaderText[1]} content={firstDropdownTemplate} /> <TabItemDirective header={tabItemsHeaderText[2]} content={secondDropdownTemplate} /> </TabItemsDirective> </TabComponent> </div> );}const root = ReactDOM.createRoot(document.getElementById('element'));root.render(<App />);
    import { useRef } from 'react';import * as React from "react";import * as ReactDOM from 'react-dom';import { TabComponent, TabItemDirective, TabItemsDirective } from '@syncfusion/ej2-react-navigations';import { DatePickerComponent } from '@syncfusion/ej2-react-calendars';import { DropDownListComponent } from '@syncfusion/ej2-react-dropdowns';const App = () => { const tabObj = useRef<TabComponent>(null); const Dropdown = (props: any) => { return ( <div> <DropDownListComponent dataSource={props.data} placeholder="Select a game" /> </div> ); } const addButtonClicked = (e: any): void => { const newTabItem = [ { header: { text: 'DynamicTabItem' }, content: thirdDropdownTemplate } ]; tabObj.current.addTab(newTabItem as any, 1); } const removeButtonClicked = (e: any): void => { tabObj.current.removeTab(1); } const firstDropdownTemplate = () => { let sportsData = [ 'Badminton', 'Basketball', 'Cricket', 'Golf', 'Hockey', 'Rugby' ]; return <Dropdown data={sportsData} />; } const secondDropdownTemplate = () => { let sportsData = [ 'Cricket', 'Golf', 'Hockey', 'Rugby', 'Badminton', 'Basketball' ]; return <Dropdown data={sportsData} />; } const thirdDropdownTemplate = () => { let sportsData = [ 'Rugby', 'Badminton', 'Basketball', 'Cricket', 'Golf', 'Hockey' ]; return <Dropdown data={sportsData} />; } const datePickerTemplate = () => { return ( <div> <DatePickerComponent /> </div> ); } let tabItemsHeaderText: any = [ { text: 'DatePicker' }, { text: 'Dropdown' }, { text: 'Reused Dropdown' } ]; return ( <div id='container'> <button id="add" className="e-btn" onClick={addButtonClicked} > Click to add </button> <button id="remove" className="e-btn" onClick={removeButtonClicked} > Click to remove </button> <TabComponent id="tabElement" ref={tabObj} > <TabItemsDirective> <TabItemDirective header={tabItemsHeaderText[0]} content={datePickerTemplate} /> <TabItemDirective header={tabItemsHeaderText[1]} content={firstDropdownTemplate} /> <TabItemDirective header={tabItemsHeaderText[2]} content={secondDropdownTemplate} /> </TabItemsDirective> </TabComponent> </div> );}const root = ReactDOM.createRoot(document.getElementById('element'));root.render(<App />);

    ×

    Adding dynamic items with content reuse in React Tab component (1)

    Adding dynamic items with content reuse in React Tab component (2024)
    Top Articles
    The Importance of Working Capital Management | TimesPro blog
    The latest property price report from Spain: Are Spanish house prices going up or down?
    Get Directions To Home Depot
    Play Retro Games Online - NES, SNES, GBA, GBC, NEO-GEO & More
    Beat Still - DesdemonaKaylose - Hanna Is Not A Boy's Name
    Vcuapi
    Danielle Ranslow Obituary
    Free Inter Tv Live
    Examples of "Crocodile" in a Sentence
    247 Recruiting Calculator
    Craigslist Ft Meyers
    Life And Wealth Mastery Fiji Cost
    Wal-Mart 2516 Directory
    Quooker Nordic Zeepdispenser Zwart ZPNBLK | bol
    50 Shades Of Grey Movies123
    Über mich - Über Charly-G - Über Karl-Heinz Gebhardt
    Pokemon Infinite Fusion How To Get All Starters
    Play It Again Sports Knoxville Photos
    Elite Dangerous Sensor Fragments
    War Thunder M60
    Fine Taladorian Cheese Platter
    Energy Healing Conference Utah
    Umbreon GX #SM36 Prices | Pokemon Promo
    24 Hour Drive Thru Car Wash Near Me
    1980 Monte Carlo For Sale Craigslist
    Baris Atay Twitter
    Different Types of Nameplates, Nameplate Materials & More
    E8 Markets Review - Forex Prop Reviews
    Fortnite Unblocked Games 66
    First Daughter | Rotten Tomatoes
    Ernesto Deleon Fox
    Dit zijn de 14 beste restaurants van Amsterdam
    Aveda Institute Brandon Photos
    belarus studio│bingサジェスト検索結果履歴│
    Isabella Lauren Leak
    2003 Chevrolet Corvette Z06 Coupe On for sale - Portland, OR - craigslist
    Dislocated Shoulder Bg3
    Chromazz Bikini
    Why did Sean 'Diddy'​ Combs give me his mobile number?
    Is Buffalo Bills Singletary Related To Mike Singletary
    Wash World Of Lexington Coin Laundry
    ما ملكت أيمانكم (مسلسل) - المعرفة
    Funny Walking Gif
    Week 2 NFL Power Rankings: 1-32 poll, plus which newcomer had the best performance for every team?
    Thotalife
    R. Kelly trial: A look at the key moments after star found guilty
    Breckie Hill Shower Cucumber
    eValuations – BlueBird Valuation
    Mugfaces Beaufort South Carolina
    Lesser Illustrious Insight Wow
    Chastity Brainwash
    Latest Posts
    Article information

    Author: Amb. Frankie Simonis

    Last Updated:

    Views: 6442

    Rating: 4.6 / 5 (56 voted)

    Reviews: 87% of readers found this page helpful

    Author information

    Name: Amb. Frankie Simonis

    Birthday: 1998-02-19

    Address: 64841 Delmar Isle, North Wiley, OR 74073

    Phone: +17844167847676

    Job: Forward IT Agent

    Hobby: LARPing, Kitesurfing, Sewing, Digital arts, Sand art, Gardening, Dance

    Introduction: My name is Amb. Frankie Simonis, I am a hilarious, enchanting, energetic, cooperative, innocent, cute, joyous person who loves writing and wants to share my knowledge and understanding with you.