Skip to content

Use key inside a React class in 0.12+ #2591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
khmylov opened this issue Nov 24, 2014 · 1 comment
Closed

Use key inside a React class in 0.12+ #2591

khmylov opened this issue Nov 24, 2014 · 1 comment

Comments

@khmylov
Copy link

khmylov commented Nov 24, 2014

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.

@zpao
Copy link
Member

zpao commented Dec 10, 2014

See #2429

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

No branches or pull requests

2 participants