I have a variable in component1 but I need to call that variable in component2 and I haven't been able to do it, this is the code I have:
component1:
import React from 'react'
function Componente1() {
global.url_login='https://www.deportes.mipagina.com/api/usuarios/';
return (
<div>
</div>
)
}
export default Componente1
component2 :
import React from 'react'
import Componente1 from './Componente1'
console.log("url" + global.url_login);
function Componente2() {
return (
<div>
</div>
)
}
export default Componente2
The traditional way to set a static attribute to a function is as follows
Then in your component you declare it as follows.
And to access it, you simply have to put the name of the imported function and the attribute you want to access.