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.


Related Query

More Query from same tag