The issue seems to be with how you're setting the checked property of the checkbox. The checked property of a checkbox should be a boolean, but in your code, you're setting it to a string value.
In your useFormik hook, you're setting is_active to a string value, when it should be a boolean. You can convert the string to a boolean using JSON.parse().
Here's how you can fix it:
const formik = useFormik({
initialValues: {
module_id: action === "create" ? "" : `${data.pengurusan_menus_module_id}`,
menu_id: action === "create" ? "" : `${data.menu_id}`,
title: action === "create" ? "" : `${data.title}`,
url: action === "create" ? "" : `${data.url}`,
icon: action === "create" ? "" : `${data.icon}`,
is_active: action === "create" ? false : JSON.parse(data.is_active),
},
...
})
In the above code, JSON.parse(data.is_active) will convert the string "true" to true and "false" to false.
Also, in your Checkbox component, you're passing value prop which is not necessary for checkbox input. You can remove that.
export default function Checkbox({ id, name, handleChange, checked }) {
return (
<input
type="checkbox"
id={id}
name={name}
className="rounded border-gray-300 text-indigo-600 shadow-sm focus:ring-indigo-500"
onChange={(e) => handleChange(e)}
checked={checked}
/>
);
}
Now, your checkbox should correctly reflect the is_active state from your database.