Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

76
Views
Reaccionar componente SVG usando objetos

Estoy tratando de obtener SVG en un archivo de objeto. luego usa SVG como este.

 import {CustomIcons} from "./Icons" <CustomIcons name="FrameIcon" /> <CustomIcons name="VectorIcon" />

Solo quiero importar un archivo y obtener un ícono personalizado basado en el nombre. He estado intentando esto durante horas y estoy perdido.

CustomIcon.tsx

 export const CustomIcons = { FrameIcon: ( <svg width="632" height="330" viewBox="0 0 632 330" fill="none" xmlns="http://www.w3.org/2000/svg" > <path d="M460.923 -287.339L760.908 192.738C748.744 201.994 736.08 210.636 723.487 219.419C695.409 238.987 667.885 262.248 636.416 276.436C612.104 287.397 589.793 302.386 564.742 311.911C523.785 327.491" fill="#232323" /> </svg> ), VectorIcon: ( <svg width="632" height="330" viewBox="0 0 632 330" fill="none" xmlns="http://www.w3.org/2000/svg" > <path d="M460.923 -287.339L760.908 192.738C748.744 201.994 736.08 210.636 723.487 219.419C69" fill="#232323" /> </svg> ), };
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Veo un par de problemas aquí, trataré de explicar tanto como pueda:

  1. Se supone que el tipo del valor exportado (por ejemplo, FrameIcon) es una función. Por ejemplo, su archivo debería exportarse de esta manera:
 export { FrameIcon: () => ( <svg width="632" height="330" viewBox="0 0 632 330" fill="none" xmlns="http://www.w3.org/2000/svg" > <path d="M460.923 -287.339L760.908 192.738C748.744 201.994 736.08 210.636 723.487 219.419C695.409 238.987 667.885 262.248 636.416 276.436C612.104 287.397 589.793 302.386 564.742 311.911C523.785 327.491" fill="#232323" /> </svg> ), VectorIcon: () => ( <svg width="632" height="330" viewBox="0 0 632 330" fill="none" xmlns="http://www.w3.org/2000/svg" > <path d="M460.923 -287.339L760.908 192.738C748.744 201.994 736.08 210.636 723.487 219.419C69" fill="#232323" /> </svg> ), };
  1. Se supone que la importación es: import { FrameIcon } from './Icons'

Consejos adicionales

Cree una carpeta llamada Icon, cree los siguientes archivos en ella:

  • index.js
  • FrameIcon.jsx
  • VectorIcon.jsx

Su index.js debería exportar todos los íconos creados en esta carpeta, por ejemplo:

 export * from './FrameIcon'; export * from './VectorIcon';

Su FrameIcon , por ejemplo, debería ser:

 const FrameIcon = () => ( <svg width="632" height="330" viewBox="0 0 632 330" fill="none" xmlns="http://www.w3.org/2000/svg" > <path d="M460.923 -287.339L760.908 192.738C748.744 201.994 736.08 210.636 723.487 219.419C695.409 238.987 667.885 262.248 636.416 276.436C612.104 287.397 589.793 302.386 564.742 311.911C523.785 327.491" fill="#232323" /> </svg> ) export { FrameIcon };

Espero que esto ayude.

about 4 years ago · Juan Pablo Isaza Report

0

Debe definir CustomIcons como componente de función

Algo como esto debería funcionar

 import React from 'react'; const CustomIcons = (props) => { const icons = { FrameIcon : <svg width="632" height="330" viewBox="0 0 632 330" fill="none" xmlns="http://www.w3.org/2000/svg" > <path d="M460.923 -287.339L760.908 192.738C748.744 201.994 736.08 210.636 723.487 219.419C695.409 238.987 667.885 262.248 636.416 276.436C612.104 287.397 589.793 302.386 564.742 311.911C523.785 327.491" fill="#232323"/> </svg>, VectorIcon: <svg width="632" height="330" viewBox="0 0 632 330" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M460.923 -287.339L760.908 192.738C748.744 201.994 736.08 210.636 723.487 219.419C69" fill="#232323"/> </svg> } return <> {icons[props.name]} </> }; export default CustomIcons; `
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!