score:0
Accepted answer
katia wheeler is correct. if you want to stay with the promise only. then inside you second then
where you have your console.log
you can use this.setstate
.
fetch('https://api.github.com/users/krunallathiya')
.then(res => res.json())
.then(json => {
this.setstate({
graphdata: json,
})
});
then you will have it in the component state and you can use it normally from there.
score:2
assign the response to a variable and then call setstate
with the data like so:
updated with async
const response = await fetch('https://api.github.com/users/krunallathiya')
.then(res => res.json());
this.setstate({
data: response
});
then you can access your response using this.state.data
in render for the graph.
Source: stackoverflow.com
Related Query
- How do I use data from a Fetch request in the state?
- How to send data from react and use the request body in express, using Axios?
- How to use useEffect() to fetch data from an api in a useReducer() and useContext() state management setup?
- How to take the result from a fetch request and insert data into jsx?
- How can I pass the data from a POST request to my global state with Redux?
- How to add objects retrieved from fetch request to the state array in React and then update the view?
- How do I use data from POST request for the next GET request
- How do i set the state from one API call and use the data for URL in next API call?
- How to fetch API data from Axios inside the getServerSideProps function in NextJS?
- How to put a dynamic data from firestore in the function where() and also use the snap.size to count the total query to be passed in a graph?
- How to fetch data in getInitialProps with redux-saga.Then get the response from redux store while in the getInitialProps method?
- How can I use react useContext , to show data from context, in the same component
- How to use the global data from React inside Apollo client's initialization?
- How to retrieve data from the server using fetch get method and show it in a table
- How to make React.js fetch data from api as state and pass this state data from its parent to child component
- How to update the state after a data update through an API request in React?
- How do I correctly add data from multiple endpoints called inside useEffect to the state object using React Hooks and Context API?
- How to fix the state update in react while getting data from firestore database
- React: How to use multiple Contexts of the same type while allowing children to read data from all of them
- How to use a variable in which data is fetched from mongoDB , in another file where we can use the data stored in that variable
- How get data from the state and edit the element in the form?
- In React, how can a parent component set state from the response an async fetch function performed in a child component?
- How to push the data from api to my initial state list items using the redux toolkit?
- How to fetch json data from a url that requires an api key to access the data in reactjs?
- React - how to set state with the data from a resolved promise
- How to use UseEffect() hook to load data from the backend to material table?
- How to use data from fetch correctly in React document title?
- How to pass the data from a state to a Formik initialValues?
- How to check and return value of state object array and use that to identify which object to take data from
- How to use mapStateToProps to get a value from the state based on a context value?
More Query from same tag
- How to render programmatically created table in React?
- TypeScript error - property component does not exist on React mui MenuItem
- React js - update table rows after ajax call
- How to use typescript with the definition of custom styles for a select using react-select
- support for the experimental 'jsx' isn't currently enabled
- How to fix nextCreate is not a function setting up useMemo setting up authentication react router and hooks
- How do I style a div inside a component without passing props to that component (I'm using a package)
- Why do I get TypeError: undefined is not an object (evaluating 'items.items.map') when removing a component?
- How to update state of a component which uses two context consumers
- ReactJS writing stateless function comments
- How to preserve aspect ratio upon resizing browser containing a react-lottie component?
- React Router render component on a separate page
- How to package to 'production' my react website with Webpack?
- How to display a boolean status to be active or inactive
- Set Material UI Table cell background colour based on cell value using Javascript?
- GeoChart with react-google-charts doesn't work
- If else condition while maping through object json in react
- Fetch all Names in Option Value, but getting only 1
- Why does the Airbnb style guide say that relying on function name inference is discouraged?
- Ternary Operator if else if issue
- Cannot read property 'match' of undefined error
- reactjs menu hide on blur with toggle class
- Converting object to array to map over
- Server Side Render Dynamic Page based on Route Param
- How can I render multiple components interpolating JSX?
- Babel loader unable to import React
- Making UI Components Selectable in ReactJS
- How to convert object to string in react js
- NULL value returned when trying to fetch data from solidity smart contract from react js
- React-router-dom redirect issue