Skip to content

Commit

Permalink
use usePrevious
Browse files Browse the repository at this point in the history
  • Loading branch information
tienifr committed Nov 6, 2023
1 parent eff0a16 commit d75501f
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import withWindowDimensions, {windowDimensionsPropTypes} from '@components/withWindowDimensions';
import useCopySelectionHelper from '@hooks/useCopySelectionHelper';
import useInitialValue from '@hooks/useInitialValue';
import usePrevious from '@hooks/usePrevious';
import compose from '@libs/compose';
import getIsReportFullyVisible from '@libs/getIsReportFullyVisible';
import Performance from '@libs/Performance';
Expand Down Expand Up @@ -89,7 +90,7 @@ function ReportActionsView(props) {
const mostRecentIOUReportActionID = useInitialValue(() => ReportActionsUtils.getMostRecentIOURequestActionID(props.reportActions));

const prevNetworkRef = useRef(props.network);
const prevAuthTokenType = useRef(props.session.authTokenType);
const prevAuthTokenType = usePrevious(props.session.authTokenType);

const prevIsSmallScreenWidthRef = useRef(props.isSmallScreenWidth);

Expand Down Expand Up @@ -134,16 +135,14 @@ function ReportActionsView(props) {
}, [props.network, props.report, isReportFullyVisible]);

useEffect(() => {
const prevTokenType = prevAuthTokenType.current;
const wasLoginChangedDetected = prevTokenType === 'anonymousAccount' && !props.session.authTokenType;
const wasLoginChangedDetected = prevAuthTokenType === 'anonymousAccount' && !props.session.authTokenType;
if (wasLoginChangedDetected && didUserLogInDuringSession() && isUserCreatedPolicyRoom(props.report)) {
if (isReportFullyVisible) {
openReportIfNecessary();
} else {
Report.reconnect(reportID);
}
}
prevAuthTokenType.current = props.session.authTokenType;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [props.session, props.report, isReportFullyVisible]);

Expand Down

0 comments on commit d75501f

Please sign in to comment.