Help to eval the contect on component

Hi guys i starting to develop a platform in reactjs to learn js and actually using codemirror to create a tests-box

example : Captura de pantalla de 2020-03-26 23-15-41

i only get the code on a string, but i need the code or result of this

i trying to not use eval() to evict the risks of malicious code

the results will be evaluated with mocha.js

solutions?