ReactJS children - filter out null values
You have to take advantage of Array.filter():
const MyComponent = ({ children }) => {
// This filter will return only not null values
const children = React.Children.toArray(children).filter(Boolean);
// return ...
};
Working example:
const array = [1,2,3,null,4,null,5,null];
console.log(array.filter(Boolean));