Array object not updating in react? - reactjs

I have an application where the user will select a seat and then will click reserve and the seats will be greyed out. For some reason my object array of seats are not updating in the array and the seats are not greying out. when I log the seating sometimes, the isReserved is true, and when I log it again it goes back to false.
Here is what the code looks like:
const seats: any[] = [
{ id: 1, isSelected: false, isReserved: false },
{ id: 2, isSelected: false, isReserved: false },
{ id: 3, isSelected: false, isReserved: false },
{ id: 4, isSelected: false, isReserved: true },
{ id: 5, isSelected: false, isReserved: false },
{ id: 6, isSelected: false, isReserved: false },
];
const Seatbooking = () => {
const [isSelected, setIsSelected] = useState(0);
const [seating, setSeating] = useState(seats);
function onSelected(select: any) {
console.log(select.id);
console.log("selected ", select);
setIsSelected(select.id);
console.log("it is selected ", select.id);
}
const onReserved = (id: any) => {
setSeating((seat) => {
return seat.map((item) => {
return item.id === id
? { ...item, isReserved: !item.isReserved }
: item;
});
});
};
return (
<>
<div className="grid-container">
{seats.map((seat) => (
<div style={{ width: "50%" }}>
<button
key={seat.id}
style={{
backgroundColor:
seat.isReserved === true
? "grey"
: seat.id === isSelected
? "red"
: "#2d95c9",
}}
className="seat_buttons"
onClick={() => onSelected(seat)}
>
{seat.id}
</button>
</div>
))}
</div>
<button className="seat_booking" onClick={() => onReserved(isSelected)}>
Reserve seat
</button>
</>
);
};

Working solution with fixed naming and optimised conditions.
import { useState } from 'react';
const seats = [
{ id: 1, isSelected: false, isReserved: false },
{ id: 2, isSelected: false, isReserved: false },
{ id: 3, isSelected: false, isReserved: false },
{ id: 4, isSelected: false, isReserved: true },
{ id: 5, isSelected: false, isReserved: false },
{ id: 6, isSelected: false, isReserved: false },
];
export const Seatbooking = () => {
const [selectedSeatId, setSelectedSeatId] = useState(0);
const [seating, setSeating] = useState(seats);
function onSelected(select) {
console.log(select.id);
console.log('selected ', select);
setSelectedSeatId(select.id);
console.log('it is selected ', select.id);
}
const onReserved = (id) => {
const updatedArr = seating.map((item) => {
return item.id === id ? { ...item, isReserved: !item.isReserved } : item;
});
setSeating(updatedArr);
};
return (
<>
<div className="grid-container">
{seating.map((seat) => (
<div key={seat.id} style={{ width: '50%', display: 'flex' }}>
<button
style={{
backgroundColor: seat.isReserved
? 'grey'
: seat.id === selectedSeatId
? 'red'
: '#2d95c9',
}}
className="seat_buttons"
onClick={() => onSelected(seat)}
>
{seat.id}
</button>
</div>
))}
</div>
<button className="seat_booking" onClick={() => onReserved(selectedSeatId)}>
Reserve seat
</button>
</>
);
};
You should work with state in your component, not with constant.
You do not need callback in your setSeating.
isSelected - name for boolean value. You store id - call it selectedSeatId.
Key should be on div, not on button.

seats.map((seat) => (
You're mapping over the original array, not your state variable. Change it to:
seating.map((seat) => (

Related

React native - pressable inside Flatlist does not become disabled after state changes

I have a Flatlist of about 20 filters.
Each filter selector is a Pressable.
when either filters with id 11 or 12 is checked, filter id 14 needs to become disabled.
If filter 14 is checked, both filters 11 & 12 need to become disabled.
I am handling the state with redux.
Summary - The function is doing what it is supposed to do and the Redux state is being updated correctly. The Flatlist is getting re-rendered but the disabled state on the UI doesn't change.
This is the filters arrays -
export const area = [
{ id: 1, txt: "West shore South", isChecked: false, isDisabled: false },
{ id: 2, txt: "West shore North", isChecked: false, isDisabled: false },
{ id: 3, txt: "North shore", isChecked: false, isDisabled: false },
{ id: 4, txt: "East shore", isChecked: false, isDisabled: false },
{ id: 5, txt: "South shore", isChecked: false, isDisabled: false },
{ id: 6, txt: "Barbuda", isChecked: false, isDisabled: false },
{ id: 7, txt: "Outer Islands", isChecked: false, isDisabled: false },
];
export const access = [
{ id: 11, txt: "Car", isChecked: false, isDisabled: false },
{ id: 12, txt: "Hike", isChecked: false, isDisabled: false },
{ id: 13, txt: "Public", isChecked: false, isDisabled: false },
{ id: 14, txt: "Boat Only", isChecked: false, isDisabled: false },
];
(There are couple of extra filter arrays that are irrelevant to this question).
This is the Redux slice that handles the state -
import { createSlice } from "#reduxjs/toolkit";
import { area, access, nature, other } from "../logic/FiltersData";
export const activeFiltersSlice = createSlice({
name: "activeFilters",
initialState: {
filters: [...area, ...access, ...other, ...nature],
active: [],
},
reducers: {
updateAllFilters: (state, action) => {
state.filters = action.payload;
state.active = state.filters.filter((each) => each.isChecked);
},
},
});
export const { updateAllFilters } = activeFiltersSlice.actions;
export default activeFiltersSlice.reducer;
This is the function I used to handle the state before trying to disable buttons (products being the array of all the filters)
const handleChange = (id) => {
let temp = products.map((product) => {
if (id === product.id) {
return { ...product, isChecked: !product.isChecked };
}
return product;
});
dispatch(updateAllFilters(temp));
};
This is the same function after I added the disabled change of state.
const handleChange = (id) => {
const car = products.findIndex((item) => item.id === 11);
const hike = products.findIndex((item) => item.id === 12);
let temp = products.map((product) => {
if (id === 11 || id === 12) {
if (product.id === 14) {
if (
(id === 11 &&
products[car].isChecked &&
!products[hike].isChecked) ||
(id === 12 && !products[car].isChecked && products[hike].isChecked)
) {
return {
...product,
isDisabled: false,
};
} else {
return {
...product,
isDisabled: true,
};
}
} else if (id === product.id) {
return { ...product, isChecked: !product.isChecked };
}
}
if (id === 14) {
if (product.id === 11 || product.id === 12) {
return {
...product,
isDisabled: !product.isDisabled,
};
} else if (id === product.id) {
return { ...product, isChecked: !product.isChecked };
}
}
if (id === product.id) {
return { ...product, isChecked: !product.isChecked };
}
return product;
});
dispatch(updateAllFilters(temp));
};
This is how I render the Flatlist (Section being one array of filters)
const renderFlatList = (section) => {
const print = section.map((item, index) => {
const found = products.find(
(element) => element.id === item.id
).isChecked;
return (
<Pressable
key={item.id}
style={found ? styles.itemChecked : styles.item}
hitSlop={5}
onPress={() => handleChange(item.id)}
disabled={item.isDisabled}
>
<View style={styles.itemText}>
<Text style={found ? styles.txtChecked : styles.txt}>
{item.txt}
</Text>
</View>
<View style={styles.icon}>
<MaterialCommunityIcons
name={
found
? "checkbox-multiple-marked-circle"
: "checkbox-multiple-blank-circle-outline"
}
size={32}
color={iconColor}
/>
</View>
</Pressable>
);
});
return print;
};
I use this code to verify the Redux state is updating correctly after each click, which it does
products.map((each) => {
if (each.id > 10 && each.id < 20) {
console.log(each);
}
});
However, the filters that showing on the Redux as isDisabled: true are not becoming disabled!
Why?
Thanks
And a secondary question - if anyone have an idea how to write the handleChange() function cleaner and more efficient, that will be lovely.

How to update state individually?

I have this code below, which when I click the button, it will render the current time
But when I click again to update the new time, it will update all three at the same time. I want to update only the button I clicked
I'm guessing the problem is all three using the same state.
constructor(props) {
super(props);
this.state = {
button1: false,
button2: false,
button3: false,
};
}
onClickHandler = (type) => {
this.setState({[type]: true})
}
render() {
return (
<div>
{this.state.button1 && <div>{ this.state.curTime }</div>}
{this.state.button2 && <div>{ this.state.curTime }</div>}
{this.state.button3 && <div>{ this.state.curTime }</div>}
<div>
<Button
onClick={() => { this.getTimePress(); this.onClickHandler("button1") }}
>Button 1
</Button>
<Button
onClick={() => { this.getTimePress(); this.onClickHandler("button2") }}
>Button 2
</Button>
<Button
onClick={() => { this.getTimePress(); this.onClickHandler("button3") }}
>Button 3
</Button>
</div>
</div>
)
}
}
And I was thinking of using map() might solve the problem, but I'm having a hard time figuring out how to modify boolean for each button.
this.state = {
buttonList: [
{ id: 'button1', title: "Button 1", pressed: false },
{ id: 'button2', title: "Button 2", pressed: false },
{ id: 'button3', title: "Button 3", pressed: false }
],
};
}
this.state = {
buttons: [
{ id: 'button1', title: "Button 1", pressed: false, timePress : null },
{ id: 'button2', title: "Button 2", pressed: false, timePress : null },
{ id: 'button3', title: "Button 3", pressed: false, timePress : null }
],
};
handlePressButton (button,index) {
this.state.buttons[index].pressed = true
this.state.buttons[index].timePress= Date.now() //or new Date()
this.setState({
buttons : [...this.state.buttons ]
})
}
render () {
return (
<>
this.state.buttons.map(button => <div> Pressed at : {button.timePress || "not yet"} </div> )
this.state.buttons.map((button , index) => <Button onClick={() =>this.handlePressButton(button,index)} > {button.title} </Button> )
</>
)
}

React.js - changing text in a list

I am changing the text colour in a list when the item is clicked. Ideally, I would like to have a toggle function so only 1 item is highlighted at a time. The following code works however I can't stop thinking there is a much better way.
import React, { useState } from "react";
const listItems = [
{
id: 1,
title: "About",
selected: true,
},
{
id: 2,
title: "Contact",
selected: false,
},
{
id: 3,
title: "Products",
selected: false,
},
];
const ListView = () => {
const [menuItems, setMenuItems] = useState(listItems);
const handleListClick = (id) => {
setMenuItems([...menuItems.map((item)=> {
if (item.id === id){
item.selected=!item.selected
}
return item
})])
};
return (
<>
<ul>
{listItems.map((item, index) => {
return (
<li
key={item.id}
onClick={() => handleListClick(item.id)}
style={item.selected ? { color: "red" } : { color: "Blue" }}
>
{item.title}
</li>
);
})}
</ul>
</>
);
};
export default ListView;
Any ideas on simplifying this...
You can use the array index to update the item only without traversing the array like this
import React, { useState } from "react";
const listItems = [
{
id: 1,
title: "About",
selected: true,
},
{
id: 2,
title: "Contact",
selected: false,
},
{
id: 3,
title: "Products",
selected: false,
},
];
const ListView = () => {
const [menuItems, setMenuItems] = useState(listItems);
const handleListClick = (index) => {
const items = [...menuItems];
items[index].selected = !items[index].selected;
setMenuItems(items);
};
return (
<>
<ul>
{listItems.map((item, index) => {
return (
<li
key={item.id}
onClick={() => handleListClick(index)}
style={item.selected ? { color: "red" } : { color: "Blue" }}
>
{item.title}
</li>
);
})}
</ul>
</>
);
};
export default ListView;

How to count selected checkboxes in React functional component?

I am needing to add bit of text in the sidebar of the following code. In each section, I need to have a count of the number of checkboxes selected. Is it at all possible to do this in a functional component as I have? Any examples that I have found so far are only for class components. I would like to keep it as a functional component if possible.
I have the code below, but here is a working version too:
https://codesandbox.io/s/react-playground-forked-jgmof?file=/index.js
import React, { useState } from "react";
import ReactDOM from "react-dom";
import styled from "styled-components";
import { categoryData } from "./data";
const Menu = (props) => {
const [showPanel, togglePanel] = useState(false);
return (
<MenuWrapper>
<p>Showing 20 results</p>
<div className="button-wrapper">
<p>Filter By</p>
{categoryData.map((categorybutton, i) => (
<div key={i}>
<button key={i} onClick={() => togglePanel(!showPanel)}>
{categorybutton.category}
</button>
</div>
))}
<div>
{showPanel && (
<Sidebar>
{categoryData.map((categorysection, i) => (
<details className="dropdown-header">
<summary>{categorysection.category}</summary>
{categorysection.data.map((categorylabel, i) => (
<div key={i}>
<input
type="checkbox"
id="vehicle1"
name="vehicle1"
value="Bike"
/>
<label for="vehicle1">{categorylabel.label}</label>
</div>
))}
</details>
))}
</Sidebar>
)}
</div>
<p>Toggle</p>
<p>Clear all filters</p>
</div>
</MenuWrapper>
);
};
const MenuWrapper = styled.div`
width: 90vw;
display: flex;
justify-content: space-between;
.button-wrapper {
display: flex;
}
`;
const Sidebar = styled.div`
position: fixed;
width: 200px;
height: 100vh;
background: white;
top: 0;
left: 0;
z-index: 100000;
text-align: left;
.dropdown-header {
background: #f7f7f7;
margin: 20px;
}
`;
ReactDOM.render(<Menu />, document.getElementById("container"));
export const categoryData = [
{
category: "user",
data: [
{ checked: false, value: "Me", label: "Me" },
{ checked: false, value: "Kids", label: "Kids" },
{ checked: false, value: "Guestroom", label: "Guestroom" }
]
},
{
category: "comfort",
data: [
{ checked: false, value: "Ultra-Soft", label: "Ultra-Soft" },
{ checked: false, value: "Soft", label: "Soft" },
{ checked: false, value: "Medium", label: "Medium" },
{ checked: false, value: "Medium-Firm", label: "Medium-Firm" },
{ checked: false, value: "Firm", label: "Firm" },
{ checked: false, value: "Ultra-Firm", label: "Ultra-Firm" },
{ checked: false, value: "Unsure", label: "Unsure" }
]
},
{
category: "type",
data: [
{ checked: false, value: "Pillow Top", label: "Pillow Top" },
{ checked: false, value: "Open Coil", label: "Open Coil" },
{ checked: false, value: "Pocketed Coil", label: "Pocketed Coil" },
{ checked: false, value: "Quantum Coil", label: "Quantum Coil" },
{ checked: false, value: "Memory Foam", label: "Memory Foam" },
{ checked: false, value: "Latex", label: "Latex" },
{ checked: false, value: "Unsure", label: "Unsure" }
]
},
{
category: "budget",
data: [
{ checked: false, value: 500, label: "Under $500" },
{ checked: false, value: 1000, label: "$501 - $1000" },
{ checked: false, value: 1600, label: "1001 - $1600" },
{ checked: false, value: 2500, label: "$1601 - $2500" },
{ checked: false, value: 2501, label: "$2500 and up" },
{ checked: false, value: "Unsure", label: "Unsure" }
]
}
];
If I understand correctly, you wan't to show the total number of selected items on each category.
It would be easy if we'll create a new component for the section that will have it's own state tracking its selected items.
Let's call it CategorySection. It would then have a selected state that will be an array (empty by default) of its selected items. To update our selected state, we have to fireup a function everytime any of the checkbox is changed — if the checkbox is checked, we add the current item to our selected state otherwise it will be removed.
Then to display the total selected items, we can simply count the length of our selected state.
function CategorySection({ categorysection }) {
const [selected, setSelected] = useState([]);
function onChange(event, item) {
if (event.target.checked) {
setSelected([...selected, item]);
} else {
setSelected((prev) =>
prev.filter((currItem) => currItem.value !== item.value)
);
}
}
return (
<details className="dropdown-header">
<summary>
{categorysection.category}{" "}
{selected.length > 0 ? selected.length : null}
</summary>
{categorysection.data.map((categorylabel, i) => (
<div key={i}>
<input
type="checkbox"
id={categorylabel.value}
name="vehicle1"
value="Bike"
onChange={(event) => onChange(event, categorylabel)}
/>
<label for={categorylabel.value}>{categorylabel.label}</label>
</div>
))}
</details>
);
}
PS: You should have a unique id for every checkbox on your page.

Bind combobox to sharepoint list

This code shows how to use a combobox in a Sharepoint online webpart using react. The sample data is hard coded. How can I bind the combo box to a Sharepoint list?
```
import * as React from 'react';
import { ComboBox, Fabric, IComboBoxOption, mergeStyles,
SelectableOptionMenuItemType, Toggle } from 'office-ui-fabric-
react/lib/index';
const INITIAL_OPTIONS: IComboBoxOption[] = [
{ key: 'Header1', text: 'First heading', itemType:
SelectableOptionMenuItemType.Header },
{ key: 'A', text: 'Option A' },
{ key: 'B', text: 'Option B' },
{ key: 'C', text: 'Option C' },
{ key: 'D', text: 'Option D' },
{ key: 'divider', text: '-',
itemType: SelectableOptionMenuItemType.Divider },
{ key: 'Header2', text: 'Second heading', itemType:
SelectableOptionMenuItemType.Header },
{ key: 'E', text: 'Option E' },
{ key: 'F', text: 'Option F', disabled: true },
{ key: 'G', text: 'Option G' },
{ key: 'H', text: 'Option H' },
{ key: 'I', text: 'Option I' },
{ key: 'J', text: 'Option J' }
];
const wrapperClassName = mergeStyles({
display: 'flex',
selectors: {
'& > *': { marginRight: '20px' },
'& .ms-ComboBox': { maxWidth: '300px' }
}
});
export interface IComboBoxTogglesExampleState {
autoComplete: boolean;
allowFreeform: boolean;
}
// tslint:disable:jsx-no-lambda
export class ComboBoxTogglesExample extends React.Component<{},
IComboBoxTogglesExampleState> {
public state: IComboBoxTogglesExampleState = {
autoComplete: false,
allowFreeform: true
};
public render(): JSX.Element {
const state = this.state;
return (
<Fabric className={wrapperClassName}>
<ComboBox
label="ComboBox with toggleable freeform/auto-complete"
key={'' + state.autoComplete + state.allowFreeform /*key causes re-
render when toggles change*/}
allowFreeform={state.allowFreeform}
autoComplete={state.autoComplete ? 'on' : 'off'}
options={INITIAL_OPTIONS}
/>
<Toggle
label="Allow freeform"
checked={state.allowFreeform}
onChange={(ev: React.MouseEvent<HTMLElement>, checked?: boolean) =>
{
this.setState({ allowFreeform: !!checked });
}}
/>
<Toggle
label="Auto-complete"
checked={state.autoComplete}
onChange={(ev: React.MouseEvent<HTMLElement>, checked?: boolean) =>
{
this.setState({ autoComplete: !!checked });
}}
/>
</Fabric>
);
}
}
```
This is for a Sharepoint Online webpart using the React Framework.
I have a list of 60 cost centers and I want them to appear in a combo box with autocomplete switched on.
Sample demo(many test scenarios, just checking the logic you need):
export interface IListItem{
Id: number;
Title: string;
Body : {
Body_p1: string;
Body_p2: string;
};
}
export interface IReactExState{
controlName:string,
ControlValue:string,
windowsID:number,
showPanel:boolean,
items: IListItem[],
Options:IComboBoxOption[],
selectionDetails: {},
showModal: boolean,
autoComplete: boolean,
allowFreeform: boolean
}
export default class OfficeFabric extends React.Component<IOfficeFabricProps, IReactExState> {
private _selection: Selection;
private _allItems: IListItem[];
private _columns: IColumn[];
public constructor(props: IOfficeFabricProps,state: IReactExState){
super(props);
this._selection = new Selection({
onSelectionChanged: () => this.setState({ selectionDetails: this._getSelectionDetails() })
});
this._allItems = [
{
Id : 0,
Title : "test0",
Body : {
Body_p1: "test0_p1",
Body_p2: "test0_p2"
},
},
{
Id : 1,
Title : "test1",
Body : {
Body_p1: "test1_p1",
Body_p2: "test1_p2"
}
}
];
this._columns = [
{ key: 'Id', name: 'Id', fieldName: 'Id', minWidth: 100, maxWidth: 200, isResizable: true },
{ key: 'Title', name: 'Title', fieldName: 'Title', minWidth: 200, maxWidth: 400, isResizable: true },
{ key: 'Body', name: 'Body', minWidth: 200, maxWidth: 400, isResizable: true,onRender: (item) => (
<div>
{item.Body.Body_p1}
</div>) },
];
this.state = {
controlName:"",
ControlValue:"",
windowsID:123.4,
showPanel:false,
items:this._allItems,
Options:[],
selectionDetails: this._getSelectionDetails() ,
showModal:false,
autoComplete: false,
allowFreeform: true
};
}
private _showModal = (): void => {
this.setState({ showModal: true });
};
private _closeModal = (): void => {
this.setState({ showModal: false });
};
private _getSelectionDetails(): string {
const selectionCount = this._selection.getSelectedCount();
switch (selectionCount) {
case 0:
return 'No items selected';
case 1:
return '1 item selected: ' + (this._selection.getSelection()[0] as IListItem).Title;
default:
return `${selectionCount} items selected`;
}
}
private _onItemInvoked = (item: IListItem): void => {
alert(`Item invoked: ${item.Title}`);
};
private _showPanel = () => {
this.setState({ showPanel: true });
};
private _hidePanel = () => {
this.setState({ showPanel: false });
};
private _Save = () => {
//to do save logic
this.setState({ showPanel: false });
alert('save clicked');
};
private _onRenderFooterContent = () => {
return (
<div>
<PrimaryButton onClick={this._hidePanel} style={{ marginRight: '8px' }}>
Save
</PrimaryButton>
<DefaultButton onClick={this._showPanel}>Cancel</DefaultButton>
</div>
);
};
public componentDidMount(){
var reactHandler = this;
this.props.context.spHttpClient.get(`${this.props.context.pageContext.web.absoluteUrl}/_api/web/lists/getbytitle('TestList')/items?select=ID,Title`,
SPHttpClient.configurations.v1) .then((response: SPHttpClientResponse) => {
response.json().then((responseJSON: any) => {
let tempOptions:IComboBoxOption[]=[];
responseJSON.value.forEach(element => {
tempOptions.push({key:element.ID,text:element.Title})
});
reactHandler.setState({
Options: tempOptions
});
});
});
}
// private _onJobTitReportToChange = (ev: React.FormEvent<HTMLInputElement>, newValue?: string) => {
// this.props.onJobTitleReportToChange(newValue);
// }
public handleObjectWithMultipleFields = (ev, newText: string): void => {
const target = ev.target;
const value = newText;
var _ControlName=target.name;
this.setState({
controlName: _ControlName,
ControlValue:value
})
}
public render(): React.ReactElement<IOfficeFabricProps> {
return (
<div className={ styles.officeFabric }>
<div className={ styles.container }>
<div className={ styles.row }>
<div className={ styles.column }>
<span className={ styles.title }>Welcome to SharePoint!</span>
<p className={ styles.subTitle }>Customize SharePoint experiences using Web Parts.</p>
<p className={ styles.description }>{escape(this.props.description)}</p>
<ComboBox
label="ComboBox with toggleable freeform/auto-complete"
key={'' + this.state.autoComplete + this.state.allowFreeform /*key causes re-
render when toggles change*/}
allowFreeform={this.state.allowFreeform}
autoComplete={this.state.autoComplete ? 'on' : 'off'}
options={this.state.Options}
/>
<TextField name="txtA" value={this.state.windowsID.toString()}
onChange={this.handleObjectWithMultipleFields}/>
<TextField name="txtB"
onChange={this.handleObjectWithMultipleFields}/>
<div>
<DefaultButton secondaryText="Opens the Sample Panel" onClick={this._showPanel} text="Open Panel" />
<Panel
isOpen={this.state.showPanel}
type={PanelType.smallFixedFar}
onDismiss={this._hidePanel}
headerText="Panel - Small, right-aligned, fixed, with footer"
closeButtonAriaLabel="Close"
onRenderFooterContent={this._onRenderFooterContent}
>
<DefaultButton className={styles.tablink} text="Button" />
<ChoiceGroup
options={[
{
key: 'A',
text: 'Option A'
},
{
key: 'B',
text: 'Option B',
checked: true
},
{
key: 'C',
text: 'Option C',
disabled: true
},
{
key: 'D',
text: 'Option D',
checked: true,
disabled: true
}
]}
label="Pick one"
required={true}
/>
</Panel>
<DefaultButton secondaryText="Opens the Sample Modal" onClick={this._showModal} text="Open Modal" />
</div>
<MarqueeSelection selection={this._selection}>
<DetailsList
items={this.state.items}
columns={this._columns}
setKey="set"
layoutMode={DetailsListLayoutMode.justified}
selection={this._selection}
selectionPreservedOnEmptyClick={true}
ariaLabelForSelectionColumn="Toggle selection"
ariaLabelForSelectAllCheckbox="Toggle selection for all items"
checkButtonAriaLabel="Row checkbox"
onItemInvoked={this._onItemInvoked}
/>
</MarqueeSelection>
<a href="https://aka.ms/spfx" className={ styles.button }>
<span className={ styles.label }>Learn more</span>
</a>
<Icon iconName='Mail' />
<br/>
<Icon iconName='CirclePlus' />
<br/>
<Icon iconName='LocationDot' />
</div>
</div>
</div>
</div>
);
}
}
I ended up using this.
sp.web.lists.getByTitle("ChartOfAccounts").items.getAll().then((result: any)=>{
for(let i: number = 0; i< result.length; i++) {
const b: SPData = result[i];
const c: IComboBoxOption={key:b.Column1, text: b.CostCentreInfo};
INITIAL_OPTIONS.push(c);
}

Resources