I have an array that has initially 2 values, when I click on the add button I want to add a new object but then it tells me map is not a function. Any help is greatly appreciated. This is not my entire component but what you would need to replicate:
const Equipments = (props) => {
const [equipment,setEquipment]=useState([1,2]);
const addEq = ( ) => {
console.log('add eq')
var id = equipment.length+1;
setEquipment(equipment.push(id));
console.log('this is the id',id, 'this is the array',equipment)
};
const renderEQForm = (equipment, index) => {
return (
<>
<label>{equipment.id}</label>
<Form.Item
name={['payments', 'method']}
label="Method:"
defaultValue = 'Credit Card'>
<Select defaultValue = 'Credit Card'>
<Option value='Cash'>Cash</Option>
<Option value='Check'>Check</Option>
<Option value='Credit Card'>Credit Card</Option>
<Option value='Google Pay'>Google Pay</Option>
</Select>
</Form.Item>
<Form.Item
name={["equipment", 'brand']}
rules={[{ required: false, message: 'Missing brand' }]}
label='Brand:'
>
<Input placeholder="Brand" />
</Form.Item>
</>
)}
return (
<>
{equipment.map(renderEQForm)}
<button onClick={()=>addEq()}>Add</button>
</>
);
};
export default Equipments