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

198
Visualizações
Is there a way to override what useMemo does to determine if there's a change?

useMemo(() => expensiveFunction(), [deps]) re-executes the expensiveFunction when the deps have changed. I was wondering... is there a way to control how React will check if the deps have changed?

I would like to see if I can do a "deep" isEqual check of the dependencies rather than the shallow check much like what I did with using useReducer to implement useDeepState

import isEqual from "lodash.isequal";
import { Dispatch, useReducer } from "react";
/**
 * This is similar to the `React.useState` function except it uses
 * [lodash.isEqual](https://lodash.com/docs/4.17.15#isEqual) to perform a
 * deep comparison of the values.
 * @param initialState initial state
 * @returns state, setter
 * @category React State
 */
export function useDeepState<S>(initialState: S | (() => S)): [S, Dispatch<S>] {
  function newStateIfNotEqual(state: S, newState: S) {
    return isEqual(state, newState) ? state : newState;
  }
  if (typeof initialState === "function") {
    return useReducer(
      newStateIfNotEqual,
      null as unknown as S,
      initialState as () => S
    );
  } else {
    return useReducer(
      newStateIfNotEqual,
      initialState
    );
  }
}

https://github.com/trajano/react-hooks/blob/master/src/useStates/useDeepState.ts

about 4 years ago · Juan Pablo Isaza
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