Actualmente estoy tratando de devolver una array con algunos valores y una function que también devuelve otra array . ¿Cómo hago para que mis devoluciones sean básicamente 2 arrays en lugar de 1 array y 1 function ?
Ejemplo
const array1 = [a, b, c] const function = () => { if(something) { somevalues.map(e => { return ( <div>{e}<div> ) }) } else { othervalues.map(f => { return ( <div>{f}<div> ) }) } } return [...array1, function] ??la función en el ejemplo obviamente devuelve la función en lugar de su propio retorno, ¿cómo soluciono eso?
Necesitas
somevalues.map(...) y othervalues.map(...) entonces su función devolverá undefined .Ejemplo:
const array1 = [a, b, c] const outerFunction = () => { const innerFunction = () => { if(something) { return somevalues.map(e => (<div>{e}<div>)); // ^^^^^^ } else { return othervalues.map(f => (<div>{f}<div>)); // ^^^^^^ } } return [...array1, ...innerFunction()]; // ^^^ ^^ }const array1 = ['a', 'b', 'c']; const something = true; const func = () => { if(something) { return 'e'; } else { return 'f'; } }; console.log([...array1, func()]); //[ "a", "b", "c", "e" ]