setState when API is not having the field

Viewed 31

I want to setState for a field "payment" which is blank on API call. In the registration form this data is not set but after login on dashboard this data will be reflecting and user can select the check boxes.

I am getting error:

TypeError: Cannot read property 'payment' of undefined

How to do this?

1 Answers

Never ever touch and modify the fields directly. Always use the state to modify the fields. In your case use this.state = payment and to set the state use this.setState = payment. Hope this works.

Related