So I am building a front-end website using React, my problem stems in my Supbase API, for some odd reason my code is not return the expected data that I wanted to display as the default value in my form’s input, I examined for any error, made sure my RSL polices is read, and public, right, and I have created a row in my table which I love working on,but when I check my console for some reason I am getting undefined so idk at this point where’s the issue,the code I suspect is the following three files:
- apiSetting :
export async function getSettings() {
let { data, error } = await supabase.from("settings").select("*");
/* if (error) {
return console.error("There is an Error Be Careful");
throw new Error("There is an Error in The Code");
}*/
return data;
}
- useSetting
import { useQuery } from "@tanstack/react-query";
import { getSettings } from "../../services/apiSettings";
export function useSettings() {
const {
data: settings,
isLoading,
error,
} = useQuery({
queryKey: ["settings"],
queryFn: getSettings,
});
console.log(settings, "my hook");
if (error) {
console.error("Error fetching settings:", error);
}
return { isLoading, error, settings };
- updateSettingForm
import Form from "../../ui/Form";
import FormRow from "../../ui/FormRow";
import Input from "../../ui/Input";
import { useSettings } from "./useSettings";
function UpdateSettingsForm() {
const {
isLoading,
settings: {
minimumBookingLength,
maxBookingLength,
maxsGuestPerBooking,
breakfastPrice,
} = {},
} = useSettings;
console.log({
minimumBookingLength,
maxBookingLength,
maxsGuestPerBooking,
breakfastPrice,
});
return (
<Form>
<FormRow label="Minimum nights/booking">
<Input
type="number"
id="min-nights"
defaultValue={minimumBookingLength}
/>
</FormRow>
<FormRow label="Maximum nights/booking">
<Input type="number" id="max-nights" defaultValue={maxBookingLength} />
</FormRow>
<FormRow label="Maximum guests/booking">
<Input
type="number"
id="max-guests"
defaultValue={maxsGuestPerBooking}
/>
</FormRow>
<FormRow label="Breakfast price">
<Input
type="number"
id="breakfast-price"
defaultValue={breakfastPrice}
/>
</FormRow>
</Form>
);
}
export default UpdateSettingsForm;
In put would appreciated, thanks in advance