Skip to content

What's the purpose of "value={ this.state[top] }" in Listing 15.12 #127

@NKaufman11

Description

@NKaufman11

New to React..Going through the examples... Please help if you can

<label>Ice Cream Toppings</label>
{ this.toppings.map(top =>
<div className="form-check" key={ top }>
<input className="form-check-input"
type="checkbox" name={ top }
value={ this.state[top] }   <============================================
checked={ this.state.toppings.indexOf(top) > -1 }
onChange={ this.updateFormValueCheck } />
<label className="form-check-label">{ top }</label>
</div>
)}

State is declared as
this.state = {
name: "",
flavor: "Vanilla",
toppings: ["Strawberries"]
}

toppings has array for all selected values,, what's the purpose of this.state[top]?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions