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

200
Vistas
How to get return data from another file outside of a react component?

I am trying to get react to return data from a non-component file to a component, I am wondering if that is even possible. If you don't get what I mean here is some code:

foo.js:

import random from "./script/stuff/myfantasticfile.js";

export const myFantasticFunction = () =>{
return "Hello world!";
}

App.jsx:

import react from "react";
import Stuff from "./stuff.jsx"
import {myFantasticFunction} from "./foo.js"

function App(){
const myVariable = myFantasticFunction();
return(
<div>
<Stuff/>
<p>{myVariable}</p>
</div>
)

In other words When the code is executed the p tag will say "undefined" and cannot print "Hello world" on the screen.

I have tried to search on google, stackoverflow and some other online coding websites ie: grepper.

If anyone have any idea please share it to me by posting an answer.

kind regards Alvin.

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

0

Maybe your function is not loaded when it render the component, I suggest to try that:

<p>{myVariable ? myVariable : '' }</p>
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