Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

261
Visualizações
Function parameter explanation in Redux where a function returns a function?

I do understand Redux a bit, but I don't understand how you can put a function inside a function.

import api from '../utils/api';

import {
  GET_PROFILE, PROFILE_ERROR
} from './types';

export const getCurrentProfile = () => async (dispatch) => {
  try {
    const res = await api.get('/profile/me');

    dispatch({
      type: GET_PROFILE,
      payload: res.data
    });
  } catch (err) {
    dispatch({
      type: PROFILE_ERROR,
      payload: { msg: err.response.statusText, status: err.response.status }
    });
  }
};

I am having issues with this line:

export const getCurrentProfile = () => **async (dispatch) => {}**
  1. Are we defining our own function here with async (dispatch) => {}?
  2. Why will we define our own function?
  3. I know what dispatch does, but where do we get it and why are we using it on the two objects?
  4. What is the name of this pattern, if any?
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

  1. yes. The getCurrentProfile returns a new function that takes one parameter.

  2. Maybe they will use the function in a closure. Closures can be used to hide information.

  3. Whatever is using the function you create will give the dispatch to the function when it calls it.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda