React Hook "useSelector" used in common functions
useSelector from Redux store
Redux: useSelector vs connect
RTK: useSelector() vs store.getState()
Videos
This is my selectors.jsimport { useSelector } from 'react-redux';export const useCloseAlertTrigger = () => useSelector((state) => state.common.closeAlertTrigger || {});
this is my commonFunction.js [in this I am storing my all common functions ]export const LogoutUser = async () => {const closeAlert = useCloseAlertTrigger();if (closeAlert) {const result = await DisplayMessageOnClosebookingEdit();if (result) {return false;}}const result = await RCM_API('POST','',{service: 'service',action: 'logout',},true);if (result && result.resultCode === STATUS.SUCCESS) {window.location.href = \${window.location.origin}/${BASE_PATH}/logout`;}return true;};`
in this functions I have used useCloseAlertTrigger hook but react throws an error that hook can be called inside functions it should called inside component only , and if I make simple functions rather than hook then another error arrives like useselctor can only be used inside component or react hook , that's why I have to give the prefix use
i want to make the redux architecture common like i will make selectors functions inside selector.js and i will use that selectors in commonfunction.js and from that i will use respective function in component PS: i am using **redux-toolkit **