Skip to content

Instantly share code, notes, and snippets.

@themgoncalves
Created August 17, 2020 12:44
Show Gist options
  • Save themgoncalves/16e8513a3fdb2c18710a1ea92a37efcb to your computer and use it in GitHub Desktop.
Save themgoncalves/16e8513a3fdb2c18710a1ea92a37efcb to your computer and use it in GitHub Desktop.
Working with multiple references on React - ES6
import React from 'react';
const mergeRefs = (...refs) => (value) => {
for (let i = 0; i < refs.length; i += 1) {
const ref = refs[i];
if (typeof ref === 'function') {
ref(value);
} else if (ref) {
ref.current = value;
}
}
};
export default mergeRefs;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment