markdown-text-editor 1.9.0 → 1.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -191,8 +191,15 @@ editor.destroy();
191
191
  In React, create the editor in an effect and return `destroy` as the cleanup — that also covers StrictMode running effects twice in development:
192
192
 
193
193
  ```jsx
194
+ // Options are read once, so reach the latest onChange through a ref rather
195
+ // than rebuilding the editor whenever the parent re-renders
196
+ const onChangeRef = useRef(onChange);
197
+ onChangeRef.current = onChange;
198
+
194
199
  useEffect(() => {
195
- const editor = new MarkdownEditor(ref.current, { onChange });
200
+ const editor = new MarkdownEditor(ref.current, {
201
+ onChange: (value) => onChangeRef.current?.(value),
202
+ });
196
203
  return () => editor.destroy();
197
204
  }, []);
198
205
  ```