Pages corrections journal
This commit is contained in:
parent
becae5e646
commit
f4603391ee
@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { Calendar, Activity, Heart, Pill, Droplet, Dumbbell, FileText } from 'lucide-react';
|
||||
|
||||
interface HealthData {
|
||||
@ -56,6 +56,9 @@ export const HealthForm: React.FC<HealthFormProps> = ({ content, onContentChange
|
||||
return {};
|
||||
});
|
||||
|
||||
// Use ref to track last sent content to prevent infinite loops
|
||||
const lastSentContentRef = useRef<string>('');
|
||||
|
||||
// Initialize date if not set
|
||||
useEffect(() => {
|
||||
if (!data.date && date) {
|
||||
@ -69,14 +72,15 @@ export const HealthForm: React.FC<HealthFormProps> = ({ content, onContentChange
|
||||
// Only update if content actually changed to prevent infinite loops
|
||||
useEffect(() => {
|
||||
const jsonContent = JSON.stringify(data, null, 2);
|
||||
// Only update if content is different from current content
|
||||
if (jsonContent !== content) {
|
||||
// Only update if content is different from last sent content
|
||||
if (jsonContent !== lastSentContentRef.current) {
|
||||
const timer = setTimeout(() => {
|
||||
lastSentContentRef.current = jsonContent;
|
||||
onContentChange(jsonContent);
|
||||
}, 500); // Increased delay to reduce updates
|
||||
return () => clearTimeout(timer);
|
||||
}
|
||||
}, [data]); // Removed onContentChange and content from dependencies to prevent loops
|
||||
}, [data, onContentChange]); // Stable dependencies
|
||||
|
||||
const updateField = (field: keyof HealthData, value: any) => {
|
||||
setData(prev => ({ ...prev, [field]: value }));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user