Files
frontend-app-discussions/src/data/hooks.js
Awais Ansari 0844ee6875 Perf: improved discussions MFE's components re-rendering and loading time (#513)
* chore: configure WDYR for react profiling

* perf: reduced post content re-rendering

* perf: post content view and it child optimization

* perf: add memoization in post editor

* perf: add memoization in postCommnetsView

* perf: improved endorsed comment view rendering

* perf: improved re-rendering in reply component

* fix: uncomment questionType commentsView

* fix: removed console errors in postContent area

* perf: reduced postType and postId dependancy

* perf: improved re-rendering in discussionHome

* perf: improved re-rendering of postsList and its child components

* perf: improved re-rendering of legacyTopic and learner sidebar

* fix: postFilterBar filter was not updating

* fix: resolve duplicate comment posts issue

* fix: memory leaking issue in comments view

* fix: duplicate topic posts in inContext sidebar

* perf: add lazy loading

* chore: remove WDYR configuration

* fix: alert banner padding

* chore: update package-lock file

* fix: bind tour API call with buttons
2023-05-08 16:21:29 +05:00

33 lines
1.0 KiB
JavaScript

/* eslint-disable import/prefer-default-export */
import { useState } from 'react';
import { useDispatch } from 'react-redux';
/**
* A hook that creates an enhanced version of dispatch that can track the loading state.
*
* This hook will return a boolean that tracks the current loading state, and a function
* that can be used an an alternative to dispatch for dispatching thunks. If dispatch
* is called with a thunk it's loading state will be reflected in the boolean.
*
* If you need to track multiple requests, or multiple types of requests, use multiple
* instances of this hook. e.g. one for loading and one for saving.
*
* @return {(boolean|(function(*=): Promise<void>)|*)[]}
*/
export function useDispatchWithState() {
const dispatch = useDispatch();
const [isDispatching, setDispatching] = useState(false);
const dispatchWithState = async (thunk) => {
setDispatching(true);
await dispatch(thunk);
setDispatching(false);
};
return [
isDispatching,
dispatchWithState,
];
}