Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Updating UI Based on Async Results | Handling Async Logic with Redux Toolkit
Gerenciamento de Estado com Redux Toolkit no React

bookUpdating UI Based on Async Results

Deslize para mostrar o menu

What You Are Building

Now you connect async state to the UI.

Triggering the Fetch

Dispatch the async action when the component loads:

import { useEffect } from 'react';
import { useDispatch } from 'react-redux';
import { fetchPosts } from './postsThunk';

function Posts() {
  const dispatch = useDispatch();

  useEffect(() => {
    dispatch(fetchPosts());
  }, [dispatch]);
}

Keeping UI in Sync

Once the action is dispatched:

  • Redux updates the state;
  • Components re-render automatically;
  • UI reflects the latest data.

The Result

Your UI now responds to real data:

  • Shows loading;
  • Displays results;
  • Handles errors.
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 5. Capítulo 4

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Seção 5. Capítulo 4
some-alt