I
I
igotDiamonds2019-12-04 18:19:45
JavaScript
igotDiamonds, 2019-12-04 18:19:45

React why object property returns undefined?

5de7cdae59762410136766.jpeg
there is such an object, I need to get the value of the "fields" property from it, i.e. an array and use the .map method to render the elements
Here is the implementation

get formData() {
        return this.props.deliveryFormData.payload.form;
    }

    render() {
        console.log(Object.entries(this.formData))
        return (
            <form name="delivery-form" type="post" action="/api/v1/shipping/submit_form" onSubmit={this.handleFormSubmit}>
                {
                    this.formData.fields.map(e => console.log(e.label))
                }
            </form>
        )
    }

this.formData.fields is undefined even though
console.log(this.formData.fields)
shows an array

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2019-12-04
@igotDiamonds

Because the map returned underfined(console.log() returns it).
this.formData.fields.map(e => e.label)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question