score:8
Accepted answer
You can make use of componentDidMount
function to call an api (if you want to call it only once) that returns you the data which you can save in the state and render
class App extends React.Component {
state = {
data: [],
loading: true
}
componentDidMount() {
ApiCall().then((data) => {
this.setState({data, loading: false})
})
}
render() {
if(this.state.loading) {
return 'Loading...'
}
return (
<View><Text>{this.state.data.map((obj => <View>{/* return that you want here from obj*/}</View>))}</Text></View>
);
}
}
To enhance UserExperience, you can have a loading state till your data is ready.
Source: stackoverflow.com
Related Query
- Data unavailable before render method is executed - React Native
- render method being called before API data is loaded in React
- React native + redux populate store with data before any Component render
- React fetch data in server before render
- Wait for API call data before render react hooks
- React Native Element Type is Invalid. Check Render Method
- Wait for API data before render react hooks
- React - Loading data before render
- How do I fetch data from API before render method called? (react, passport, express)
- React Redux - load response data before render
- ReactJS is calling the render method before it receives the data to render
- Using React hook to run Mobx method before initial render of component
- Check the render method of 'PodCastScreen' React Native
- React showing component before going through the render method
- React fetch data before render class component
- React Native Fetch data from API - BUT not render in flat list, just single time
- How can I fetch data in server before render in react isomorphic app?
- then() method is executing before the data is actually returned in react
- React native error of Check the render method of App
- Method called on render without click react native
- React & Mobx: render (via method render()) @observable data that will be modified after the specified component is rendered
- Page tries to render before data is loaded from API - React
- How to fetch data before render functionnal component in react js
- Functions is executed before the data is taken from state in React Javascript
- React Component's render method called twice even after data fetched
- React Redux fetch data before render and do a map function
- React - Render happening before data is returned and not updating component
- trying to fetch data from api and show it in react native flatlist and my code displays data in console log,but it didnt render in emulator
- How to use data from a callback function in the render method in a react class
- Rendering React components with promises inside the render method
More Query from same tag
- Generate two different index files for RTL and LTR support using Webpack
- What is a proper way to manipulate DOM elements outside of Provider component in React + Redux.js app?
- Correctly Navigating to React Route from Javascript
- fluent ui - How to display/overlay a Spinner component in a TextField where iconProps usually renders the icon?
- How to get the index of an array map , out of the map function in React
- How to implement virtual scroll for 4 images in a row using React js
- How to structure the css files in reactjs in a way that it follows the concept of component separation
- react classNames using two conditional classes
- Reactjs-setState previous state is the first argument, props as the second argument
- Compare Two different arrays and update array of objects with useState in React
- How to set Formik initialValues using interpolated strings?
- Network graph using d3.js
- Date string to date object
- Grid / Array of documents not loading on first click
- Error Objects are not valid as a React child (found: Invalid date)
- React parent component needs child function to return data
- Add js lib to react component
- Custom contents <td> in ReactJS
- React fader component fade direction not changing
- React/Redux - Manage state of table with multiple columns of checkboxes
- Select form field not populating with options from state in ReactJS
- Material Table inner onClick shows only last row value
- Resolving ESLint / React / Redux (Airbnb config) errors that don't seem to make sense
- What is the correct way to add an event listener to the window in React?
- Typescript IndexOf Issue in Array<String> useState
- process.env is undefinined and I cannot read variable from it
- NPM install, totally unknown -E prefix
- "How to update value of item initialized from getDerivedStateFromProps on some action"?
- What is the best way of assigning a variable from an object value in React?
- How to optimize update of object array in useReducer?