Это мой обзор кода:
Сначала у меня есть хук, который выполняет все операции с этим объектом с использованием GraphQL:
Код: Выделить всё
// useRecommendation.js
...
// other operations
export const useUpdate = () => {
const [updateCriteria, { loading, error }] = useMutation(UPDATE_CRITERIA);
const update = { handle: updateCriteria, loading, error };
return update;
};
Код: Выделить всё
// Recommendation.js
const Recommendation = {
all: useGetAll,
byCategory: useGetByCategory,
create: useCreate,
update: useUpdate
}
export default Recommendation
Код: Выделить всё
export const useRecommendationFormHandler = ({ form }) => {
const updateRecommendation = Criteria.update();
const submitRecommendation = async () => {
try {
const { data } = await updateRecommendation.handle({
variables: {
input: {
conformity: form.conformity,
importance: form.importance,
comment: form.comment,
conclusion: form.conformity === 0 && form.importance !== null,
},
criteria_id: form.id
}
});
return data;
} catch (error) {
console.error("Erro ao atualizar a criteria", error);
}
};
return {
isLoading: updateRecommendation.loading
}
};
Код: Выделить всё
{forms.length !== 0 && criterias.data.map((data, i) => (
f.id === data.id)}
onChange={handleChange}
index={i}
onRefetch={onRefetch}
/>
))
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... sedebounce
Мобильная версия