Skip to content

artemkaint/react-child-by-ref-decorator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-child-by-ref-decorator

ECMA-6 Decorator for separate React children by ref property

Micro decorator allows you to access child node by ref property. Decorator wraps base component into component and transmits associated object through childrenByRef property into base component

Example

// Inner component
import childByRefWrapper from 'react-child-by-ref-decorator';

@childByRefWrapper
export default class Switcher extends React.Component {

  render() {
    return <div>
      <div>{this.props.childrenByRef.refA}</div>
      <div>{this.props.childrenByRef.refB}</div>
    </div>;
  }
}


// Main component
import Switcher from 'Switcher';
export default class Main extends React.Component {

  render() {
    return <Switcher>
      <div ref="refA"></div>
      <div ref="refB"></div>
      <div ref="refC"></div>
    </Switcher>;
  }
}

About

ECMA-6 Decorator for separate React children by ref property

Resources

License

Stars

Watchers

Forks

Packages

No packages published