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

306
Visualizações
React functional component - State is changed, component is re-rendered but DOM is not updating

I'm facing a weird issue with react functional components.

Context

I have a parent component with two state objects. On useEffect hook, I'm making an API call and setting the state with received response data, and then I'm processing this raw data with some attributes and setting this in the second state.

And on click event of an input element, I'm again processing the raw data(with another set of attributes) which I saved in the first state and then setting this processed data to the second state object.

So everything is working as expected. State object is updating in the initial rendering and on click event also this state is being updated and component re-renders

But the problem is with the DOM, the DOM is not reflecting this state change. I'm wondering what could be the reason. I'm adding some pseudocode to emulate the same scenario.

function ParentComponent = () => {
  const [rawData, setRawData] = useSate({});
  const [data, setData] = useState({});

  const handleClick = ({attr: 'new attr'}) => {
    const getProcessedData = processData(rawData, { attr });
    setData(getProcessedData);
  }

  useEffect(() => {
    const fetchData = async () => {
      const res = await fetch('apiurl');
      setRawData(res);
      const getProcessedData = processData(res, { attr:'process based on this attr'});
      setData(getProcessedData);
    }
    fetchData();
  }, [])

  return (<Container>
    <button onClick={() => handleClick({attr: 'new attr'})}>Click me</button>
    //Here the child component recieves the updated data on click event but its not reflecting the DOM.
    <Child data={data} /> 
  </Container>);
}

Any helps would be appreciated. Thanks in advance.

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