Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

571
Vistas
How to properly import custom icons created with IcoMoon in react native component (expo)

I have created custom icons. If I try to use the icons in App.js it works fine. I want to use them in my other files. What is the proper way of doing it?


import { createIconSetFromIcoMoon } from "@expo/vector-icons";

const Icon = createIconSetFromIcoMoon(
  require("./components/SVGComponents/selection.json"),
  "IcoMoon",
  "icomoon.ttf"
);

const fetchFonts = () => {
  return Font.loadAsync({
    ...

    //icons font
    IcoMoon: require("./components/SVGComponents/icomoon.ttf"),
  });
};


export default function App() {
  const [isFontLoaded, setIsFontLoaded] = useState(false);
  if (!isFontLoaded) {
    return (
      <AppLoading
        startAsync={fetchFonts}
        onFinish={() => setIsFontLoaded(true)}
        }
      />
    );
  }
...
}

I tried creating an Icon component, importing it in the App.js file and then using it in other component of mine but I am getting the following errors :

Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

AppLoading threw an unexpected error when loading: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

//Icon.js
import { createIconSetFromIcoMoon } from "@expo/vector-icons";


const fetchFonts = () => {
  return Font.loadAsync({
   ...

    //icons font
    IcoMoon: require("./components/SVGComponents/icomoon.ttf"),
  });
};

export default Icon = createIconSetFromIcoMoon(
  require("./components/SVGComponents/selection.json"),
  "IcoMoon",
  "icomoon.ttf"
);

//in App.js
import Icon from "./components/SVGComponents/Icon";

Also tried with export const Icon and import {Icon} , got the same error

in the component i want to use icons:

<Icon name="Back" color="green" size={44}></Icon>

What did the job - exporting Icon from App.js and importing it in the component I want to use it like that:

import { Icon } from "../../App";

but I am not sure it's a good idea to use it this way. How would you suggest I use it?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Solved it like this:

//Icon.js
import { createIconSetFromIcoMoon } from "react-native-vector-icons";

export default createIconSetFromIcoMoon(
  require("./selection.json"),
  "IcoMoon",
  "icomoon.ttf"
);

In the file I want to use the icon:

import Icon from "../SVGComponents/Icon";

Then

//App.js
const fetchFonts = () => {
  return Font.loadAsync({
 

    //icons font
    IcoMoon: require("./components/SVGComponents/icomoon.ttf"),
  });
};



export default function App() {
  const [isFontLoaded, setIsFontLoaded] = useState(false);
  if (!isFontLoaded) {
    return (
      <AppLoading
        startAsync={fetchFonts}
        onFinish={() => setIsFontLoaded(true)}
        onError={(err) =>
          console.log("App => fetchFonts,  <AppLoading> => " + err)
        }
      />
    );

   ...
  }

in a folder called SVGComponents I have placed the icon font file - icomoon.ttf, the icons - selection.json, the custom icon component - Icon.js

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda