score:1
do you need to bind fetchapitoentries in the constructor or use fat arrows?
this.fetchapitoentries = this.fetchapitoentries.bind(this);
sorry i cant comment not enough rep
score:2
idk what your api response is but i tested your code with a fake api and changed
fetchapitoentries(apitofetch){}
to arrow function (arrow function)
fetchapitoentries = (apitofetch) => {}
and it's working fine.
full example:
export default class portfolio extends react.component {
constructor(props) {
super(props);
this.state = {
entries: []
}
}
componentdidmount() {
this.fetchapitoentries('https://jsonplaceholder.typicode.com/posts');
}
fetchapitoentries = (apitofetch) => {
fetch(apitofetch)
.then(result => result.json())
.then((entries) => {
this.setstate({
...this.state,
entries
})
})
.catch((error) => console.log(error));
}
render() {
const {entries} = this.state;
console.log(entries);
return (
// everything you want to render.
)
}
}
hope it helps you.
Source: stackoverflow.com
Related Query
- React componentDidMount fetch api
- How to import external data fetch api into react componentDidMount method
- React - componentDidMount API call does not fetch data?
- Is it possible to ignore ssl verification for fetch api in react app?
- React Fetch to Laravel API Creates New Session
- React - Fetch from external API function on button click
- Fetch api post call returning 403 forbidden error in React js but the same URL working in postman
- Post an object with fetch using react js and express API server
- How to handle fetch API AJAX response in React
- How to set timeout in Fetch API using react js
- CORS error using fetch API - React create app
- React Hook useEffect : fetch data using axios with async await .api calling continuous the same api
- displaying data from fetch api using react
- Express does not receive parameters via POST from React using Fetch API
- ReactJS componentDidMount and Fetch API
- How do I test async fetch in react componentDidMount with chained promises?
- React hook with fetch api
- React js fetch API
- How to fetch and display data from Express API to a React app?
- React fetch all data from api at startup
- Search functionality and fetch api in React
- React setState fetch API
- fetch POST returns only _id object in Express API server React FrontEnd
- React / Axios: fetch API data with key for CoinMarketCap
- Fetch API can't load '.php' local file - React JS + PHP
- Fetch from componentDidMount in React JS
- How to fetch api via looped callbacks with React functional components
- React API Handle Error in Fetch Call : TypeError-Cannot read property 'temp' of undefined
- Fetch foreign key object instead of ID in React from Django API
- Is it right concept if I used Async Await with react life cycles specially with ComponentDidMount for api calls?
More Query from same tag
- how to get the unique id in firebase
- Multiple panels open and close at one click - Ant Design Collapse
- How to use Abort Controller to abort APIs initiated from inside useEffect but triggered by user action?
- Error on build in Heroku -pre-received hook declined but why?
- React error when compiling with webpack
- React Testing with history passed
- Why my data from an api is still undefined?
- React input type="number" for floats
- How to add key to React Component object
- covert list into another new list with new property name
- Web app getting zoomed in chrome
- Why is my onSubmit not working in PrimeReact Dialog?
- Difference between "const" outside component and "static" inside component?
- Uncaught Error: Actions must be plain objects?
- Material UI Textfield Can't Change Font Size for Multiline
- Unable to connect component to Redux store
- React with TypeScript - React has detected a change in the order of Hooks called by ComponentName
- How to dynamically specify screens in React Navigation based on contents of redux store?
- React-table - disable global filter for one column, but add another filter for disabled one
- Redux word for a function that changes state
- Performance implications of implementing 2-way data binding in React
- How to set one component data into other component
- How to resize canvas according to the parent div element (react)?
- What's the difference between functions that render JSX vs. declaring components inside another component?
- Expected mock function to have been called one time, but it was called zero times. in react
- How to export a variable inside render function (React JS)?
- useSelector not updating even after dispatch
- adding hammerjs to a react js component properly
- apollo-client used to make multiple requests to make a real-time search
- Gutenberg React - Struggling to use withSelect