In my React code snippet, I am encountering an issue with the organizationId
variable. Even though I can see its value in the first and second instances, I am unable to see it in the third instance. This strange behavior is occurring in a Next.js based project.
function Event(props: EventProps) {
const { lang, translations, eventId } = props;
const [event, setEvent] = useState<EventOut | undefined>();
const [enableSaleSwitch, setEnableSaleSwitch] = useState<boolean>(false);
const [
enableSaleSwitchOnWordpress,
setEnableSaleSwitchOnWordpress,
] = useState<boolean>(false);
let isTiketAdmin: string | null;
let jwt: string | null;
let eventIdNew: string | undefined;
let organizationId: string | undefined;
let organization: OrganizationOut | undefined;
let userFbId: string | null;
let permission: string | undefined;
useEffect(() => {
isTiketAdmin = localStorage.getItem("isTiketAdmin");
jwt = localStorage.getItem("jwt");
userFbId = localStorage.getItem("userFbId");
}, []);
useEffect(() => {
organizationId = getOrganizationFbIdFromEventId(eventId);
if (organizationId != undefined) {
organization = getOrganizationByFbId(organizationId!);
if (organization && userFbId) {
permission = organization.usersWithPermission[userFbId];
setEvent(organization.events[eventId]);
}
}
}, [eventId]);
useEffect(() => {
if (event) {
if (checkEnableSaleOnTiket(event, eventId)) {
setEnableSaleSwitch(true);
} else {
setEnableSaleSwitch(false);
}
if (checkEnableSaleOnWordPress(event, eventId)) {
setEnableSaleSwitchOnWordpress(true);
} else {
setEnableSaleSwitchOnWordpress(false);
}
}
}, [event]);