Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.
This repository was archived by the owner on Sep 21, 2022. It is now read-only.

Allow multiple refs per element / Multiple elements per ref #19

@nmn

Description

@nmn

This is not a common case, but there are times when it would be great to be able to put multiple refs to the same Element.

Additionally, refs, currently work like ids, where every ref has a one-to-one relationship with a single element. It would be great to be able to have a similar system that works a lot more like a class.

Example:

var App = React.createClass({

  componentDidMount: function(){
    var refs = this.refClass.focussed;

    refs.forEach(function(ref){
      var el = ref.getDOMNode();
      var rect = el.getBoundingClientRect();

      el.classList.add(someFunction(rect));
    });
  },

  render: function(){
    return React.DOM.div({ref: ['container'], refClass:['div', 'focussed']},
      React.DOM.span({ref: ['span'], refClass:['focussed']})
    );
  }

});

The value is not obvious for making general apps, but it makes a whole set of additions on top of React possible. Currently the closest thing we have is a hack workaround where refs are names with sequential names — a1, a2 ...

When in javascript, it should really be possible to just use arrays for things like this, as with sequential names, you need to know the number of refs before hand.

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