Answer the question
In order to leave comments, you need to log in
How to insert values into an object field using SetState?
I'm writing an application in React, making a form and ran into a problem.
There is a model
PrePaymentParameters.ts
export interface PrePaymentParameters {
PartnerId: number;
OrderNumber: string;
WebSite: string;
AccountNumber: string;
Sign: string;
SumValue: number;
EmailClient: string;
EmailOperator: string;
NumberTransactions: number;
SumTransaction: number;
}
import * as React from "react";
import 'bootstrap/dist/css/bootstrap.min.css';
import Field from '../../components/Field/Field';
import Form from '../../components/Form/Form';
import ContentHeader from '../../components/ContentHeader/ContentHeader';
import { PrePaymentParameters } from '../../models/Orders/Operations/PrePaymentParameters'
import {
Card,
CardBody,
Col,
Row,
} from 'reactstrap';
import Axios from "axios";
export interface IFormState {
submitSuccess?: boolean;
prePayment: PrePaymentParameters;
}
export default class PaymentByCardPage extends React.Component<{}, IFormState> {
constructor(props: {}) {
super(props);
this.state = {
prePayment: {
PartnerId: 766,
OrderNumber: "",
WebSite: "sa",
AccountNumber: "",
Sign: "gdfgmsdlkfdfngjm",
SumValue: 0,
EmailClient: "[email protected]",
EmailOperator: "[email protected]",
NumberTransactions: 5,
SumTransaction: 500
}
};
}
<Field id="SumValue" label="Сумма предоплаты" onChange={e => this.setState({ prePayment: {SumValue : 1000 } })}
Answer the question
In order to leave comments, you need to log in
I would make the first question through https://github.com/kolodny/immutability-helper/ (update() method).
Second question, is your SumValue: 0 not suitable?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question