All my variables in the component are depending on the variable passed in params.
Why should I create state for all of them? I would just create variable with let
, like:
let isTiketAdmin: string | null = null;
let jwt: string | null = null;
let organizationId: string | undefined = undefined;
let organization: OrganizationOut | undefined = undefined;
and load in value in a method:
const load = () => {
isTiketAdmin = localStorage.getItem("isTiketAdmin");
jwt = localStorage.getItem("jwt");
userFbId = localStorage.getItem("userFbId");
const organizationList = JSON.parse(
localStorage.getItem("organizationList") ?? "[]"
);
organizationId = getOrganizationFbIdFromEventId(eventId);
let organization: OrganizationOut | undefined;
if (organizationId) {
organization = organizationList[organizationId];
let event = organization!.events[props.eventId];
And when something needs to be saved/changed, call load()
.
But then how will rendering work? Do you have any good suggestion to rerender without calling setState
?