newrelic / nr1-workshop

Self-paced training workshop for the NR1 CLI/SDK
Apache License 2.0
86 stars 68 forks source link

Simplying the code on Lab 2 #35

Closed tangollama closed 5 years ago

tangollama commented 5 years ago

From @swachs

The Button call in the second StackItem here doesn’t seem to do anything different from the first one (a direct call to this.openEntity()). openEntity() doesn’t make use of any passed in parameters.

<NerdletStateContext.Consumer>
...
        } else if (nerdletUrlState && nerdletUrlState.entityGuid) {
...
                <StackItem>
                    <Button onClick={() => {
                        this.openEntity(nerdletUrlState.entityGuid)
                    }}>Open {nerdletUrlState.appName}</Button>
                </StackItem>
...
</NerdletStateContext.Consumer>

You can rewrite this as follows, and get the same result:

<StackItem>
    <Button onClick={this.openEntity}>Open {nerdletUrlState.appName}</Button>
</StackItem>