I am unable to use useSelector and useDispatch in export const function.
export const StartTelecalling = (piopiy, userId, password) => {
const { modal, isTestCall, isOnline } = useSelector((state) => state.calls);
const dispatch = useDispatch();
piopiy.login(userId, password, "sbcind.telecmi.com");
console.log("login Initiated..............");
piopiy.on("login", (object) => {
console.log(object);
// if (object.code === 200) {
console.log("login successfully......");
// dispatch(setIsOnline(true));
// }
});
}
In the above code I am getting invalid hook call at useSelector and useDispatch and I have multiple exports like that I can't declare as default export.
You cannot call hooks inside nested functions, loops, conditions or regular JS functions as per React documentation. Also, React Hooks can only be called at the top level. Apparently, you are calling the hooks inside a regular JS function. Calling these hooks inside a functional react component might solve the issue.