const appendString = (children) => {
if (Array.isArray(children)) {
return children.reduce((acc, current) => {
if (typeof current === 'string') {
return acc.concat(current);
} else if (typeof current === 'object') {
return acc.concat(current.props.children);
} else {
return acc;
}
}, '');
} else {
return children + ''; // <-- Fix
}
};
It doesn't necessarily return a string type all the time, so have to force string.
const appendString = (children) => { if (Array.isArray(children)) { return children.reduce((acc, current) => { if (typeof current === 'string') { return acc.concat(current); } else if (typeof current === 'object') { return acc.concat(current.props.children); } else { return acc; } }, ''); } else { return children + ''; // <-- Fix } }; It doesn't necessarily return a string type all the time, so have to force string.