Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

131
Vistas
How to export multiple functions Javacript?

I want to export default all functions inside export default, but every time I try to import them in another file, I get the error that the functions don't exists. Am I importing wrong?

export default () => {

  // methods
  const makeRequest = async () => {

    async function useAllBenefits() {
      ...
    return payload;
    }

    async function useTopBenefits() {
     ...
    return payload;

    }

    // exposed
    return {
      useAllBenefits,
      useTopBenefits,
      makeRequest
    };
  };
}

myotherfile.js

import all from '../myFile'

console.log(all.useAllBenefits)
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

  1. Don't put them inside another function
  2. Use the export keyword

Such:

export const aFunction = () => {};
export const anOtherFunction = () => {};
const someDefaultExport = () => {};
export default someDefaultExport;

Then you can import them:

import theDefault, { aFunction, anOtherFunction } from "../myFile";
about 4 years ago · Juan Pablo Isaza Denunciar

0

If you want to export multiple functions AS DEFAULT you can do it by exporting one object whose properties are functions.

export default {
   function1: () => {},
   function2: () => {},
   function3: () => {}
}

Now in another file you can import them and use as bellow:

import all from '../myFile.js';
all.function1();
all.function2();
about 4 years ago · Juan Pablo Isaza Denunciar

0

Method 1. export each functions

myFunction.js

export const sum = (a,b) {
   return a + b;
}

export const multiply = (a,b) {
   return a * b;
} 

Method 2.

myFunction.js

const sum = (a,b) {
   return a + b;
}

 const multiply = (a,b) {
   return a * b;
} 

export default {sum, multiply}

Import section

file.js

import all from './myFunction.js'

all.sum(10, 11);

Or file.js

import {sum, multiply} from './myFunction.js'

sum(10, 11);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda