Skip to content

Use key inside a React class in 0.12+ #2591

@khmylov

Description

@khmylov

Quite often, our apps need to render a list of entities.
Entities usually contain some data and an identifier property like id or key.
Sometimes we may have some logic inside a component which uses that identifier, e.g. uses it inside some click handler to fire an event with id of the clicked entity.

Here is a simplified example:

var Entity = React.createClass({
    notifyItem: function() {
        fire('someEvent', { id: this.props.key });
    },

    render: function() {
        return <div onClick={this.notifyItem} />;
    }
});

We also find it natural to use these properties as a key prop when rendering a list for a proper component recycling.

However, with 0.12 key was moved out of props, and it doesn't seem to be available inside a component at all, so now we have to specify two different props-like values, which looks redundant:

<Entity
    key={...}
    entityId={...} />

Would be great to make key available inside a component once again in the future versions.

Metadata

Metadata

Assignees

No one assigned

    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