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