Skip to content

Instantly share code, notes, and snippets.

@paulshen
Created April 13, 2021 16:11
Show Gist options
  • Save paulshen/9889b6067609f9053a0d56d464164cad to your computer and use it in GitHub Desktop.
Save paulshen/9889b6067609f9053a0d56d464164cad 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