'use strict';

/**
 * Given an array of refs, merge them into a single ref callback.
 * This is useful for cases where you need to pass a multiple refs to a component.
 */
function mergeRefs(refs) {
    return value => {
        refs.forEach(ref => {
            if (typeof ref === "function") {
                ref(value);
            }
            else if (ref != null) {
                ref.current = value;
            }
        });
    };
}

exports.mergeRefs = mergeRefs;
