I have problem that i get an error when using the ternary operator to check which React Hook to use. The message is:"React Hook "useIsolationDynamicPhase" is called conditionally. React Hooks must be called in the exact same order in every component render." Do anyone happen and know how to fix it.
Thank you.
export default function Edit({ isPhasedIsolation }: Props) {
const { phaseId, methodId } = useParams<{ phaseId: string; methodId: string }>();
const method = isPhasedIsolation ? usePhaseMethod(+phaseId, +methodId) : useMethod(+phaseId, +methodId);
const phase = isPhasedIsolation ? useIsolationDynamicPhase(+phaseId) : useIsolationPhase(+phaseId);
const [checked, setChecked] = useState<boolean>(Boolean(method?.currentState));
const save = useSave(method as IsolationMethod, +phaseId, checked, phase?.phaseType as string, isPhasedIsolation);
if (method === null) return null;
return (
<EditTabLayout
onSave={save}
disableSaveButton={Boolean(method?.currentState) === checked}
title={`${getLabel('button.label.update')} ${getLabel('print.activity.status')}`}>
<Container>
<DisplayField label={getLabel('mobile.isolation.plannedState')}>
<TruncatedText text={method.plannedState} />
</DisplayField>
</Container>
<Container>
<Row>
<Label>{getLabel('dashboard.activityGrid.column.currentState')}</Label>
<Switch checked={checked} onChange={e => setChecked(e.value)} />
</Row>
</Container>
</EditTabLayout>
);
}
I have read some solution in many website but i can not find out the suitable solution for this situation. I want only one react hook is called in this case.