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
Source: stackoverflow.com
Related Query
- Exporting the output of an API as an object
- Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema
- Invalid options object. Dev Server has been initialized using an options object that does not match the API schema
- Webpack error: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema
- ValidationError: Invalid options object. CSS Loader has been initialised using an options object that does not match the API schema
- PostCSS Loader has been initialized using an options object that does not match the API schema
- how to avoid "Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema."
- Get object array from axios and using return value call another axios function and append the output to first result
- Webpack has been initialised using a configuration object that does not match the API schema. webpack install by "npm install webpack"
- I get data from Api but when I try to set the value with useState it give me an empty object
- I can't access the object what I want from Poke API
- Cannot assign to read only property 'approved_by_customer_admin' of object '#<Object>' after updating the api data manually
- Unable to render the JSON object in a list from Github issues api
- Module not found: Invalid generator object. Asset Modules Plugin has been initialized using a generator object that does not match the API schema
- Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema. 2022 problem
- How to output the cat_Id of a category sent by an api on clicking that category
- Cannot Display the Data From the object from an API
- Webpack 5.47.1 : Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema
- append/add/unshift an object to the beginning of an response from an api
- Fetching data from API and using it in JSX is giving string output to the html tag
- How can I access google api script on the window object in next.js app?
- Axios instance for API call body payload ( creating the common object for all API)
- How can I mutate my state without having to reload the entire json object via the API
- Is there any efficient pdf library in react which gets the base64 content from API and displays the output in the form of pdf?
- I have spent the last 8 hours trying to pass a simple JSON object with some data from an api through my express backend to one of my react components
- Trying to iterate over a nested object from an API and return the data into my react component
- Can't map an object, fetching an api returns first undefined then the object
- How is it possible that after API call and setState, some elements of the same object are accessible, while others aren't?
- In delete operation the api always deletes the last json object for any username or password provided?
- How to map the required data of array of object which i got from api call to usestate variable
More Query from same tag
- How to add a validation from the select renderer using the rsuite in react
- Add image to the DOM dynamically in react
- Cannot import ES2015 module
- How can I save the text value of the checkbox on Firestore?
- TextGeometry of Three.js with React not working
- Applying styling to external library component in AntDesign
- How can I access state inside of my Redux cartReucer?
- How to add styles to all infinite scroll rendering items?
- React-toastify notification won't return in conditional
- Next seven days auto date picker
- I am trying to make a matrix of buttons in React.js
- AstraDB failed GET request
- React 16.4 - manual form input fill along with its updates from getDerivedStateFromProps?
- How to fix error: Unhandled Rejection (TypeError): meetups.map is not a function
- React PropTypes: Require array to have at least one element
- Accessing filtered object values from props (JS/React)
- Difference between React.HTMLProps<HTMLDivElement> and React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>?
- React-hook-form Have to press twice for deleting the last character of input and twice for enter the first character
- Check screen size change for a specific width
- Allow accordion to only open one at a time
- useState not evaluating after history.push
- Why doesn't enzymes find() with component props work the same way when using full rendering or shallow rendering?
- Main differences between lit-element & React
- Access React Context value outside of the body of a function component
- Function runs properly when called however always returns undefined
- How convert .jsx to .js with Gulp and Babel?
- appolo-link-rest set header
- How to not to resize the content while using drawer in Material UI
- Firebase Firestore - Access document within another document of unknown id
- Password Post not working Reactjs with Nodejs server