# Keeping textArea and CodeMirror in sync

**URL:** <https://discuss.codemirror.net/t/keeping-textarea-and-codemirror-in-sync/617>\
**Category:** Uncategorized\
**Created:** [January 28, 2016, 8:57pm UTC](https://discuss.codemirror.net/t/keeping-textarea-and-codemirror-in-sync/617 "2016-01-28T20:57:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![joeltine](https://discuss.codemirror.net/letter_avatar_proxy/v4/letter/j/13edae/32.png) [@joeltine](https://discuss.codemirror.net/u/joeltine)\
**Post date:** [January 28, 2016, 8:57pm UTC](https://discuss.codemirror.net/t/keeping-textarea-and-codemirror-in-sync/617/1 "2016-01-28T20:57:32Z")

</div>

I’d like to be able to keep a textarea and the CodeMirror instance instantiated on it in sync (in terms of text content). I realize that `cm.save()` will update the textarea from the current CodeMirror state, but what if I want to update CodeMirror to reflect the current content of the textarea? It seems like re-running `fromTextArea()` does the trick, but I’m concerned this could be a heavyweight operation and even possibly lead to memory leaks.

Any suggestions? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [February 2, 2016, 10:31am UTC](https://discuss.codemirror.net/t/keeping-textarea-and-codemirror-in-sync/617/2 "2016-02-02T10:31:17Z")

</div>

There’s no built-in functionality like this, but you can listen for events on both and use `setValue` to update the CodeMirror value. Just make sure you ignore CodeMirror “change” events that you yourself caused, to avoid infinite loops.
