I need to update my state after updating / setting a different state in my useEffect hook. So far it does not work. What am I doing wrong here?
The isDisabled
logic depends on the values of the other states.
const OffersDialogueButton = ({
type,
status,
}) => {
const { invitationType, status: cardStatus } = useJobPositionsContext();
const { jobPosition } = useJobDetailContext();
const [dialogStatus, setDialogStatus] = useState<CardStatus>();
const [dialogType, setDialogType] = useState<CardType>();
const [color, setColor] = useState<string>();
const [isDisabled, setIsDisabled] = useState(false);
useEffect(() => {
setDialogStatus(status || cardStatus);
setDialogType(type || invitationType || 'default');
setIsDisabled(
(dialogType === 'invitation' && dialogStatus !== 'pending') || (dialogType === 'application' && cardStatus !== 'accepted'),
);
setColor(BUTTON_VARIANT_BY_STATUS[dialogStatus]);
}, [type, status, isDisabled]);