Skip to content

Exercise 03: Why must 'name' be explicitly used? (Spoilers) #71

Description

@qwelyt

Exercise 03, task 1.

In the onNameChange(event) function you take an event and is supposed to use that event to update the state.

The working solutions, for the tests, is to explicitly name the key, ie: this.setState({name: event.target.value});

But, if you want to be more general, and you don't want to explicitly say that it's the "name" attribute that should always be updated, you can do this:

onNameChange(event){
   let obj = {};
   obj[event.target.name] = event.target.value;
   this.setState(obj);
}

Which works great in the browser, but fails in the tests.

Is there a specific reason for this that I'm missing?

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