Easy
While building a content management system, your team needs to implement a document autosave feature. What's missing from this code to prevent excessive save operations?
1function DocumentEditor() {2 const [content, setContent] = useState('');3 const [status, setStatus] = useState('saved');4 const lastSaved = useRef(null);56 // Missing autosave implementation7 const handleSave = async () => {8 try {9 await saveDocument(content);10 lastSaved.current = Date.now();11 setStatus('saved');12 } catch (error) {13 setStatus('error');14 }15 };1617 return (18 <div className="editor">19 <textarea20 value={content}21 onChange={(e) => {22 setContent(e.target.value);23 setStatus('unsaved');24 handleSave();25 }}26 />27 <div className="status">28 Status: {status}29 {lastSaved.current &&30 ` (Last saved: ${new Date(lastSaved.current).toLocaleTimeString()})`31 }32 </div>33 </div>34 );35}