Horrible Howtos - replacing findDomNode

*This is much easily covered in the Facebook documentation.

I'm not good, so I am interning with Iced Dev to become good. One of my mentors is Blaine Bublitz.... And he alerted me to a few of the newer changes with refs and es6.

If you read more about refs on the React site you can see that the recommended method is using arrow functions to create one liners.

We observe that perhaps it might be more useful to prepare our ref function in the render, and keep the return as clean as possible. We come out with something similar to this:

class HorribleComponent extends React.Component{

    // Call the ref
    const node = this._element;
    // Prepare the ref in a one liner before return, keep return clean
    const saveRef = (element) => this._element = element;
      <input ref={saveRef} type='input'/>

Calling the ref is now very easily modifiable. Some use cases I can think of are running a conversion equation(make sure you set propTypes properly).

Show Comments

Get the latest posts delivered right to your inbox.