--- layout: page --- # onlyValid() Deep filters all non React Elements ```typescript onlyValid(children: ReactNode | ReactNode[]): ReactNode[] ``` ## Arguments
children
The children array from the element where is used.
## Return Value A new children array with only valid React Elements. If there are no valid React Elements, an empty array will be returned. ## Example ```jsx import React, { ReactElement, ReactNode } from 'react'; import { render } from 'react-dom'; import { onlyValid } from 'react-children-utilities'; interface Props { children?: ReactNode; } const OnlyValid = ({ children }: Props): ReactElement =>
{onlyValid(children)}
; const Example = (): ReactElement => ( 0 text 2 3 {null} {3} {true} 4 {false} {undefined} ); render(, document.body); // Result: //
// 0 // 2 // // 3 // // 4 // // //
```