D
D
DMITRY Chernenkiy2021-05-20 15:06:04
React
DMITRY Chernenkiy, 2021-05-20 15:06:04

How to get fetch response before rendering DOM tree?

I have a small component written in react and redux. In redux, the initial state is filled with dummies. My little component has an asynchronous function inside that receives data from the Internet and inserts it into the state. And here's the problem, first the component is rendered with empty ones, and when data comes from the Internet, it re-renders with good data. That is, rendering occurs twice. How to make the component wait for
data from the Internet, and not render dummies.
Code example

export function App() {
  useEffect(getWeatherAPI, []);
  return (
    <Provider store={store}>
      <Header />
      <TimeNavigation />
      <SirchPanel />
      <DailyWeather />
    </Provider>
  );
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2021-05-20
@yarkov

if (данные) {
  <Component/>
}

So?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question