Skip to content

Instantly share code, notes, and snippets.

@yolio2003
Forked from paulshen/natto-eval.js
Created December 17, 2022 00:09
Show Gist options
  • Save yolio2003/be9d989ca49a1c918c1b7b7366b7c46e to your computer and use it in GitHub Desktop.
Save yolio2003/be9d989ca49a1c918c1b7b7366b7c46e to your computer and use it in GitHub Desktop.
natto.dev eval pseudocode
const f = useMemo(() => {
try {
return new Function('inputs', `return ${expression}`);
} catch (e) {
return [e];
}
}, [expresssion]);
// input atoms
useEffect(() => {
try {
setOutput(f(inputs));
} catch {}
}, [inputs]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment