const [effective_date_status, setEffectiveDateStatus] = React.useState(false)
I’m sending props value from parent to child. I want to set effective_date_status to false if props value is 0 & I want to set to true if props value is 1.
Can anyone help me with this issue.
>Solution :
You can do as:
const [effective_date_status, setEffectiveDateStatus] = React.useState(
!!props.value
);
or
const [effective_date_status, setEffectiveDateStatus] = React.useState(
props.value === 0 ? false : true
);
or Lazy Initialisation
const [effective_date_status, setEffectiveDateStatus] = React.useState(() =>
props.value === 0 ? false : true
);