You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have svg files stored in separate files. I want to load them in React and use as react components as below:
import SampleIcon from '@/components/editor/icons/add-column-after.svg';
<SampleIcon className="my-icon" />
I installed svgr and used in next.config.js as below:
webpack: (config) => {
// SVG
// 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: [
{
loader: '@svgr/webpack',
options: {
typescript: true,
ext: 'tsx',
},
},
],
}
);
// Modify the file loader rule to ignore *.svg, since we have it handled now.
fileLoaderRule.exclude = /\.svg$/i;
return config;
},
It works but intellisense does not work i.e. SampleIcon has any type. I tried to create declarations.d.ts file in root directory and add it in tsconfig.json in include list but does not work as well. Here is my declaration:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have
svg
files stored in separate files. I want to load them in React and use as react components as below:I installed
svgr
and used innext.config.js
as below:It works but intellisense does not work i.e.
SampleIcon
hasany
type. I tried to createdeclarations.d.ts
file in root directory and add it intsconfig.json
ininclude
list but does not work as well. Here is my declaration:Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions