Unable to control SVG with SVGR
Unanswered
West African Lion posted this in #help-forum
West African LionOP
I'm trying to follow this guide for NextJS so I can control the different aspects of an SVG. I'm not sure what I'm doing wrong though, since I can't change the colors, outline, stroke-width, etc.
This is the repo: https://github.com/EladKarni/aac-ipad-app
This is my
Here is how I tried to use an SVG:
I also added this to the
This is the repo: https://github.com/EladKarni/aac-ipad-app
This is my
next.config.mjs:/** @type {import('next').NextConfig} */
const nextConfig = {
webpack(config) {
// Grab the existing rule that handles SVG imports
const fileLoaderRule = config.module.rules.find((rule) =>
rule.test?.test?.(".svg")
);
config.module.rules.push(
// Reapply the existing rule, but only for svg imports ending in ?url
{
...fileLoaderRule,
test: /\.svg$/i,
resourceQuery: /url/, // *.svg?url
},
// Convert all other *.svg imports to React components
{
test: /\.svg$/i,
issuer: fileLoaderRule.issuer,
resourceQuery: { not: [...fileLoaderRule.resourceQuery.not, /url/] }, // exclude if *.svg?url
use: ["@svgr/webpack"],
}
);
// Modify the file loader rule to ignore *.svg, since we have it handled now.
fileLoaderRule.exclude = /\.svg$/i;
return config;
},
};
export default nextConfig;Here is how I tried to use an SVG:
import IconGood from "../../../public/icons/Icon-Good.svg";
const BoardIcon = () => {
return <IconGood />;
};
export default BoardIcon;I also added this to the
tsconfig.json file, but I'm not getting any additional info about the type. "include": ["svgr.d.ts", "next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],