score:0
Accepted answer
you can use fetch insted of axios
async componentdidmount() {
const res = await fetch(`api/info/gettablelist`)
const data = await res.json();
this.setstate({
data
})
}
or you can use like this.
async componentdidmount() {
await fetch(
`api/info/gettablelis`,
{
method: "get",
}
)
.then(data => data.json())
.then(data => {
this.setstate({
data
});
}),
}
score:0
the problem here is axios will return the response object, you need to get the data
from the response
componentdidmount() {
axios.get('api/info/gettablelist ').then(({data=[]}) => {
this.setstate({ data});
})
}
i have used shorthand syntax you can use the normal syntax
componentdidmount() {
axios.get('api/info/gettablelist ').then((res) => {
this.setstate({ data : res.data});
})
}
also please try logging the res
like
componentdidmount() {
axios.get('api/info/gettablelist ').then((res) => {
console.log(res);
this.setstate({ data : res.data});
}).catch(console.error)
}
please share the entire console log
Source: stackoverflow.com
Related Query
- How do I display a table on the home page in React JS?
- when we enter the username in login page, Home page should display Welcome {username} , how to show this using react js
- How to make the API call and display it in React JS using React Table and Axios?
- In React and React Router, how to display a header on every page except home page
- How to display the state on the same page when clicked Submit button in react
- How to display the information submitted in the html form on another page using react js?
- how to display the table using react js
- Im using React Router and I want one of my route links with path="/" to be the home page on reload.. How can you do that?
- React - Triggering click event on table row and display the selected row details in another page
- How to render list of users from firestore and display it in a table form on web page using react js?
- How to redirect from login page to home page if the authentication success in react
- React Table : How do I total (sum) values to each of the holeOne thru holeNine and display the sum as a value in out: 41?
- how to display none of the grid.col part when page is loading using react
- How to link react with redux to add and remove selected movies to the array by clicking on the heart to display them on the favoŠ³ites page
- How to display the last page when user clicks on add new row,so that user can view the newly added row using react js and prime react
- React router how to display each component on click on the same page
- How to separate home page content from the rest of the pages in react router?
- How do I wrap a React component that returns multiple table rows and avoid the "<tr> cannot appear as a child of <div>" error?
- How do I display the content of React Quill without the html markup?
- How to implement the OAuth2 Authorization code grant with PKCE for a React single page application?
- How to display the saved content of CKEditor5 in React Js
- React Flash Message: How to make the message show without refreshing the page but refresh on 200
- How do I access data returned from an axios get to display on a web page using react js?
- how to set the antd table page size in reactjs
- how to display data in table using json in react js?
- How to add page transitions to React without using the router?
- How to change the selected table row background color with React
- How to change the selected table row background using Material-UI on React
- how to update a route in React Router without re-mounting the component in a single page app?
- How to make one table record editable on button click in React when the table record is mapped?
More Query from same tag
- Redux-form not formatting post data and [object Object] issue
- Can I build sass/less/css in webpack without requiring them in my JS?
- Failing to send image to Go server
- How do I use gulp to convert all jsx files to JavaScript?
- How To Fix Invalid argument in `put` at index 0: Expected Blob or File when using React, Firebase and Filepond
- (codesandbox) How can I get all the label `checkbox` and `first option` to be checked and selected by default
- Making sidebar available for all components | React JS | React Router v6
- How to render array of objects in reactjs 1.0 with jsx?
- React JS. NavLink activeClassName ICON, IMAGE
- How to add an onClick function on an anchor tag wrapped in a string?
- Alignment with React-Bootstrap
- button loading problem (without packages )
- How to detect JS frameworks/libraries used in a page?
- Update Parent State from Child Component and send back response to child
- ReactRouter passing name of component
- What is the correct way to select one of many child elements in React?
- composing setState in react with Ramda
- React - call a child components method from Parents ComponentDidmount()
- Gatsby component shadowing
- defaultValue is not working in react DatePicker
- Webpack build - separate html, css and js output paths
- How do I change the color of this AnchorLink on scroll?
- React onClick taking an extra click to change state
- How to add a new object to an array of objects that is nested inside an array of objects in ReactJS?
- React redux doesn't return current state value
- ReactJS NodeJS: getting token from server
- Making Simple Post Request With Axios, React.js and Spring
- How to provide window width to all React components that need it inside my app?
- How to un-render component when user come from mobile device?
- How to pass onClick funtion into a span created using string literals?