forked from github/cinny
* Bump katex from 0.15.6 to 0.16.0 Bumps [katex](https://github.com/KaTeX/KaTeX) from 0.15.6 to 0.16.0. - [Release notes](https://github.com/KaTeX/KaTeX/releases) - [Changelog](https://github.com/KaTeX/KaTeX/blob/main/CHANGELOG.md) - [Commits](https://github.com/KaTeX/KaTeX/compare/v0.15.6...v0.16.0) --- updated-dependencies: - dependency-name: katex dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Remove copy-tex.css as it no longer required Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Krishan <33421343+kfiven@users.noreply.github.com>
33 lines
763 B
JavaScript
33 lines
763 B
JavaScript
import React, { useEffect, useRef } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
|
|
import katex from 'katex';
|
|
import 'katex/dist/katex.min.css';
|
|
|
|
import 'katex/dist/contrib/copy-tex';
|
|
|
|
const Math = React.memo(({
|
|
content, throwOnError, errorColor, displayMode,
|
|
}) => {
|
|
const ref = useRef(null);
|
|
|
|
useEffect(() => {
|
|
katex.render(content, ref.current, { throwOnError, errorColor, displayMode });
|
|
}, [content, throwOnError, errorColor, displayMode]);
|
|
|
|
return <span ref={ref} />;
|
|
});
|
|
Math.defaultProps = {
|
|
throwOnError: null,
|
|
errorColor: null,
|
|
displayMode: null,
|
|
};
|
|
Math.propTypes = {
|
|
content: PropTypes.string.isRequired,
|
|
throwOnError: PropTypes.bool,
|
|
errorColor: PropTypes.string,
|
|
displayMode: PropTypes.bool,
|
|
};
|
|
|
|
export default Math;
|