--- layout: page --- # groupByType() Returns an object with keys that map each tag name to an array of children of that type, and a key that maps the rest of children. ```typescript groupByType(children: ReactNode | ReactNode[], types: (ComponentClass | FunctionComponent | string)[], rest?: string): { [name: string]: ReactNode[] } ``` ## Arguments
children
The children array from the element where is used.
types
The types of elements that will be grouped. Different kind of types can be passed
  • Tag name string
  • React Element name string
  • React Element function
  • React Element class
rest
The name of the group where the remaining elements will be grouped into.
## Return Value A new children array with the elements and their children that get produced by the callback function. ## Example ```jsx import React, { ReactElement, ReactNode } from 'react'; import { render } from 'react-dom'; import { groupByType } from 'react-children-utilities'; interface Props { children?: ReactNode; } const MyElement = (): ReactElement =>
; const Grouped = ({ children }: Props): ReactElement => { const groups = groupByType(children, ['span', 'i', 'MyElement'], 'rest'); return (
{groups.span}
{groups.rest}
{groups.MyElement}
{groups.i}
); }; const Example = (): ReactElement => ( 1 2 3 ); render(, document.body); // Result: //
//
// // 1 // // // 2 // //
//
// 3 //
//
// //
//
//
```