-1

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?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
János
  • 32,867
  • 38
  • 193
  • 353

1 Answers1

1

You can force re-renders:

  1. Class components: https://reactjs.org/docs/react-component.html#forceupdate
  2. Hooks: React - How to force a function component to render? (The hooks solution would need a state but that can be extracted out to a separate custom hook)
Mohaimin
  • 664
  • 4
  • 10