import SelectOption from '../SelectOption';

/**
 * Convert children of `<SelectOptions>` components to array of options.
 *
 * @param {array} childrenArray - Array of `<SelectOptions>` components
 * @returns {array}
 */
function parseSelectOptions(childrenArray = []) {
    const results = [];

    childrenArray.forEach((child) => {
        if (child && child.type === SelectOption) {
            results.push(child.props);
        }
    });

    return results;
}

export default parseSelectOptions;

import { Children } from 'react';
import SelectOption from '../SelectOption';

/**
 * Convert children of `<SelectOptions>` components to array of options.
 *
 * @param {ReactChildren} children - children of `<SelectOptions>`
 * @returns {array}
 */
function parseSelectOptions(children) {
    const results = [];

    Children.forEach(children, (child) => {
        if (child && child.type === SelectOption) {
            results.push(child.props);
        }
    });

    return results;
}

export default parseSelectOptions;

Use 'React.Children.forEach()' to handle where children might not be array
Use 'React.Children.forEach()' to handle where children might not be array
