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

154
Vistas
Export without Render function in React Native

In my React Native application, i am trying to add a component where i'll perform some config tasks but that component won't render anything. I have made the component already but when i import that on App.tsx the fucntion doesn't get called. How to import this following component properly to App.tsx. The component is given below:

var androidVersion = VersionInfo.appVersion;
var iosVersion = VersionInfo.buildVersion;

function usePrevious(value) {
    const ref = useRef();
    useEffect(() => {
      ref.current = value;
    });
    return ref.current;
}

const Config = () => {
    console.log('check if get called >>',showVersionCodeStatus);
    const prevAmount = usePrevious(iosVersion);
    useEffect(() => {
        if(prevAmount.iosVersion !== iosVersion) {
         // process here
        }
        if(prevAmount.androidVersion !== androidVersion) {

            // process here
        }
    }, [iosVersion,androidVersion])
    // return {showVersionCodeStatus};
    
}

export default Config;

i'm importing the component in my App.tsx like the following:

import './config';

But it doesn't call the Config function. I have tried the following too:

import Config from './config';

That doesn't seem to work too. What am i doing wrong?

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

0

Since Config does not render anything, you should export it as a custom hook with a name such as useConfig. Subsequently you can import and use your custom hook in App.tsx, which will then run the config tasks specified in your useConfig custom hook.

useConfig.ts

var androidVersion = VersionInfo.appVersion;
var iosVersion = VersionInfo.buildVersion;

function usePrevious(value) {
   const ref = useRef();
   useEffect(() => {
     ref.current = value;
   });
   return ref.current;
}

const useConfig = () => {
   console.log('check if get called >>',showVersionCodeStatus);
   const prevAmount = usePrevious(iosVersion);
   useEffect(() => {
       if(prevAmount.iosVersion !== iosVersion) {
        // process here
       }
       if(prevAmount.androidVersion !== androidVersion) {

           // process here
       }
   }, [iosVersion,androidVersion])
   // return {showVersionCodeStatus};
   
}

export default useConfig;

App.tsx

import useConfig from "./useConfig";

export default function App() {
  const config = useConfig();
  return (
      ...
  );
}

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