Skip to content

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

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]?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions