score:0

you must create a variable that indicates whenever the data has been loaded or not.

const url= "someurl";
    
let obj;
let loaded = false;

fetch(url)
    .then(response => response.json())
    .then(data => obj = data)
    .then(() => loaded = true)


export default {
    obj
};

then you must pass that value to the component where you are trying to render the data.

render <company loaded={loaded} />

and then when you render the comp

you should do something like:

import react, { useeffect } from 'react';


function company() {

    useeffect(() => {

console.log(obj)

    });

    return (
        {props.loaded ? <div classname="centered">your data is: {json.stringify(obj)} </div> : "loading..."}
    )
};

export default company;

if you want to import and object and manage it globally without having to pass the props down. i recommend using redux-thunk / redux-saga for async global store requests


Related Query

More Query from same tag