reactjsstrapireact-hook-form

TypeError: Cannot read properties of undefined (reading 'value')


Why when reloading the page I get the TypeError: Cannot read properties of undefined (reading 'value'), if qualifiersValues is undefined it works but if it has a value it gives that error, it only gives that error on F5, if I change it to requisitionId it will update and put the right value on the select, but if I press F5 I get that error.

This is where I set the qualifiersValues:

                const requisitionDetail: IRequisition = {
                    id: requisition.id,
                    documentId: requisition.documentId,
                    answersUntilDate: requisition.answersUntilDate
                        ? new Date(requisition.answersUntilDate)
                        : '',
                    deliveryLimitDate: requisition.deliveryLimitDate
                        ? new Date(requisition.deliveryLimitDate)
                        : '',
                    description: requisition.description,
                    qualifiersValues: requisitionId || [],
                    submissionDate: new Date(requisition.submissionDate),
                    requisitionStatus: requisition.requisitionStatus,
                    attachments: requisition.attachments ? files : '',
                    purchaseRequisitionItems:
                        requisition.purchaseRequisitionItems ? articles : '',
                };
                setRequisition(requisitionDetail);
                reset(requisitionDetail);

my useForm():

  const { control, trigger, reset } = useForm({
        defaultValues: {
            deliveryLimitDate: '',
            answersUntilDate: '',
            qualifiersValues: [],
        },
        schema,
    });

My controlledSelect:


<ControlledSelect
   options={options}
   control={control}
   onChangeValue={handleRequestCategoryUpdate}
   name="qualifiersValues"
/>

updating the field is working and the rest is all working, only thing is not working is displaying the correct id of the qualifiersValues.

Can someone help me with this please?


Solution

  • I found what was causing the error, I had a set of options coming from database, those options were still not loaded so that error was occurring, it got resolved with a simple {options.length >=1 &&...