+
Skip to content

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

@qwelyt

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?

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

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载