Created
August 17, 2020 12:44
-
-
Save themgoncalves/16e8513a3fdb2c18710a1ea92a37efcb to your computer and use it in GitHub Desktop.
Working with multiple references on React - ES6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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