Last active
February 14, 2018 13:36
-
-
Save sjorsvanheuveln/59b9a94f8a10b35fd8f19912efed6acf to your computer and use it in GitHub Desktop.
Display Math or Formulae in ReactJS using ES6.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { Fraction, toTex } from 'algebra.js'; | |
import { Node, Context } from 'react-mathjax'; | |
function Formula(props) { | |
return ( | |
<Context input="tex"> | |
<Node inline>{props.tex}</Node> | |
</Context> | |
); | |
} | |
export default function FractionDisplay() { | |
const a = new Fraction(1, 5); | |
const b = new Fraction(2, 7); | |
const answer = a.multiply(b); | |
const question = <Formula tex={`${toTex(a)} × ${toTex(b)} = ${toTex(answer)}`} />; | |
return ( | |
<div> | |
{question} | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment