Skip to content

Array of references. #1899

@Nutelac

Description

@Nutelac

E.g, when I generate list of buttons, I want to assign every button to same array, which is accessible through this.refs. After that, I can perform operation on every button easily. Something like square bracket syntax <input type="text" name="input[]" /> in html.

var ButtonList = React.createClass({
    render: function() {
        return (
            {this.props.buttons.map(function(button) {
                return <MyButton ref="buttons[]" onClick={this.handleClick} label={button.label} />;
            })}
        );
    },
    handleClick: function() {
        this.refs.buttons.forEach(function(button) {
            // perform operation on button
        });
    }
});

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