This is a minimal example of an Astro project that uses the Mafs library to render a beautiful mathematical visualization.
-
Make a new Astro project (
npm create astro@latest
). I used theminimal
template and all of the default settings. -
Add React via the React Astro integration (
npx astro add react
). -
Add Mafs via the Mafs installation instructions (
npm install --save mafs
). -
At this point, we're mostly there! I created a React component containing the Hello f(x) example at
src/components/demo.jsx
, imported this component intosrc/pages/index.astro
, and rendered it (<HelloFx client:load />
). (Don't forget the client directive!) -
Key Step: Update
astro.config.msj
to contain the following:
import { defineConfig } from "astro/config";
import react from "@astrojs/react";
// https://astro.build/config
export default defineConfig({
integrations: [react()],
vite: {
ssr: { noExternal: ["mafs"] },
},
});
At this point, you should be able to npm run dev
to start the development server and see your Mafs coordinate plane in action!
Happy visualizing! 🚀📈