mirror of
https://github.com/vector-im/element-call.git
synced 2024-11-15 00:04:59 +08:00
Use useMemo
in a proper way in ClientContext
This commit is contained in:
parent
6998555ad9
commit
647599a39e
@ -22,6 +22,7 @@ import {
|
|||||||
createContext,
|
createContext,
|
||||||
useContext,
|
useContext,
|
||||||
useRef,
|
useRef,
|
||||||
|
useMemo,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { useHistory } from "react-router-dom";
|
import { useHistory } from "react-router-dom";
|
||||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||||
@ -263,11 +264,9 @@ export const ClientProvider: FC<Props> = ({ children }) => {
|
|||||||
}, [initClientState?.client, setAlreadyOpenedErr, t])
|
}, [initClientState?.client, setAlreadyOpenedErr, t])
|
||||||
);
|
);
|
||||||
|
|
||||||
const [state, setState] = useState<ClientState | undefined>(undefined);
|
const state: ClientState = useMemo(() => {
|
||||||
useEffect(() => {
|
|
||||||
if (alreadyOpenedErr) {
|
if (alreadyOpenedErr) {
|
||||||
setState({ state: "error", error: alreadyOpenedErr });
|
return { state: "error", error: alreadyOpenedErr };
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let authenticated = undefined;
|
let authenticated = undefined;
|
||||||
@ -280,7 +279,7 @@ export const ClientProvider: FC<Props> = ({ children }) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
setState({ state: "valid", authenticated, setClient });
|
return { state: "valid", authenticated, setClient };
|
||||||
}, [alreadyOpenedErr, changePassword, initClientState, logout, setClient]);
|
}, [alreadyOpenedErr, changePassword, initClientState, logout, setClient]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user