ReasonJun

Redux: PersistGate 본문

Frontend/Redux

Redux: PersistGate

ReasonJun 2023. 8. 20. 12:21
728x90

PersistGate is a component provided by the Redux Persist library to delay the rendering of your app's UI until your persisted state has been retrieved and saved to Redux. This can be useful for preventing your app from rendering with incomplete or stale data.

 

PersistGate takes two props:

  • loading: This prop can be a React element that will be rendered while the persisted state is being loaded.
  • persistor: This prop is the persistor returned by the persistStore function.

Here is an example of how to use PersistGate:

import { PersistGate } from 'redux-persist/integration/react';

const App = () => (
  <PersistGate loading={<Loading />} persistor={persistor}>
    <MyApp />
  </PersistGate>
);

In this example, we are using PersistGate to delay the rendering of the MyApp component until the persisted state has been loaded. If the persisted state is not available, the Loading component will be rendered instead.

 

The PersistGate component is a convenient way to ensure that your app's UI is always rendered with the latest data. It is a useful tool for any application that needs to persist its state between app launches.

 

Here are some of the benefits of using PersistGate:

  • It ensures that your app's UI is always rendered with the latest data.
  • It prevents your app from rendering with incomplete or stale data.
  • It is easy to use and configure.
  • It is compatible with React and React Native.
728x90

'Frontend > Redux' 카테고리의 다른 글

Redux : toolkit : persistReducer & persistStore  (0) 2023.08.20
Redux : toolkit : abort()  (0) 2023.08.20
Redux : createAsyncThunk  (0) 2023.08.20
Redux : toolkit : createAction / createReducer  (0) 2023.08.19
Redux : toolkit API : configureStore()  (0) 2023.08.19
Comments