A
A
Alexander2021-03-24 15:25:30
React
Alexander, 2021-03-24 15:25:30

How to flash data from server to initialState redux?

How can I hardcode the avatar of which was uploaded to the server to the initial state of redux, so that when the page is refreshed, the data is not reset, I will be grateful for the answer

let initialState = {
  posts: [] as Array<PostType>,
  profile: null as ProfileType | null,
  avatar: null as PhotosType | null,
  status: '',
  isEdit: false,
}


case 'SN/PROFILE/SAVE_PHOTO_SUCCESS': {
      return {
        ...state,
        avatar: action.photos,
      }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gimir, 2021-03-24
@axrising

Use localStorage. At the first request, save, then when initializing the store, try to get the necessary data from localStorage, if not, make a request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question