the-happy-programmer / the-happy-programmer-nextjs

Programming Courses
https://thehappyprogrammer.com/
1 stars 1 forks source link

remove SvgToReact.tsx #8

Closed MyNameIsBond closed 10 months ago

MyNameIsBond commented 10 months ago

This component is widely used in the project it should be removed as it causes a cumulative shift layout.

and in NextJS 14 it does not work properly

MyNameIsBond commented 10 months ago

update: No need to do that, I updated the logic behind it, no errors now

MyNameIsBond commented 10 months ago

import React, { ReactElement } from 'react'

interface SvgIconProps {
  name: string
  [key: string]: any 
}

const SvgtoReact: React.FC<SvgIconProps> = ({
  name,
  ...props
}: SvgIconProps): ReactElement | null => {
  try {
    const svg = require(`../public/svg/${name}.svg`).default

    return React.createElement(svg, { ...props })
  } catch (error) {
    console.error(`SVG file not found for ${name}`)
    return null
  }
}

export default SvgtoReact