Hi all I have following code:
const BasicInformation = () => {
const { Panel } = Collapse;
const dataFromBackend = [
{ id: 2, depositeAmt: '500' },
{ id: 3, depositeAmt: '1500' },
];
const totalCount = dataFromBackend
.map((item) => item.depositeAmt)
.reduce((prev, curr) => +prev + +curr, 0);
const onSubmit = (data) => {
console.log(data);
};
return (
<Form onFinish={(e) => onSubmit(e)}>
<Form.List name="users" initialValue={dataFromBackend}>
{(fields, { add }) => {
return (
<>
total Deposit Amount: $ {totalCount}
<Button
onClick={() => {
add();
}}
block
>
Add
</Button>
{fields.map((field, i) => (
<Collapse
key={i}
accordion
>
<Panel header="Amount : ">
<Form.Item
name={[field.name, 'depositeAmt']}
label="Amount"
fieldKey={[field.fieldKey, 'depositeAmt']}
>
<Input />
</Form.Item>
</Panel>
</Collapse>
))}
</>
);
}}
</Form.List>
<Button type="primary" htmlType="submit">
send
</Button>
</Form>
);
};
I am receiving some date from backend dataFromBackend and reducing to get count of all deposit Amount.
Also in collapses I have deposit label. The idea is when user changing deposit field value the total Deposit Amount: and <Panel header="Amount : "> should also dynamically changed.
I try this but it not help me to resolve it:
<Form.Item
name={[field.name, 'depositeAmt']}
label="Amount"
fieldKey={[field.fieldKey, 'depositeAmt']}
>
<Input onChange={(e)=>totalCount + e} />
</Form.Item>
Please help me to fix this problem, thank you very much.
add()function