Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

564
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda