Lucifier129 / react-lite

An implementation of React v15.x that optimizes for small script size
MIT License
1.73k stars 98 forks source link

References in stateless components don't work (but do in full react) #84

Closed sceutre closed 7 years ago

sceutre commented 7 years ago

I encountered this when trying to use drop down menus from http://blueprintjs.com. Here is a small example:

class Wrapper extends React.Component {
   render() {
       return <div><Stateless /></div>;
  }
}

function setRef(c) {
   console.log("ref from a stateless component", c);
}

const Stateless = (props) => <div ref={setRef}>Hello, world</div>;

When rendered, the console log displays in full react but not react-lite.

Looking at the code, I can fix it by doing the following, but I'm not sure if this is the best solution or has any other impacts:

  1. Remove the velem.refs check in initVelem
  2. in attachRef and detachRef move the refs check to the bottom of the method (eg just before they are used).
Lucifier129 commented 7 years ago

Thx feedback, I think you are totally right.

And already fixed it at this commit, version 0.15.28 of react-lite support this pattern now.

sceutre commented 7 years ago

Thanks! Works for me now.