3

When I used SuperAgent I didn't have this problem, but I decided to use Window.fetch polifyl and I met this problem. I see all data was loaded, but it still shows error. Could your help me identify this error please: Screen Shot

In render() I genereate a list of components based on an obtained list:

    render() {

    if (this.state.data.list) {
        console.log("render: " + this.state.data.list);
        var counter = 0;
        const list = this.state.data.list.map((item) => {
....
2
  • you are not closing 1st thenable call. Commented Feb 4, 2017 at 23:39
  • I imagine it like that: after obtaining response, sent this response to a next function and the result of that function I send to a next function, but I didn't return any result. It means I don't transfer any data without return value from functions in the chain of functions.... Commented Feb 6, 2017 at 0:29

2 Answers 2

6

The promise handlers in your screenshot won't work:

.then((json) => console.log('parsed json: ', json))
.then((json) => { this.setState({ data: json }); })

"Take the value from resolving this promise and pass it to console.log. Then, take console.log's return value (which is undefined) and pass it to this.setState."

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for hint! fetch(url, { headers: { 'Accept': 'application/json', }, }).then((response) => response.json() .catch(err => { console.err('${err}' happened!); return {}; })) .then((json) => { console.log('parsed json: ', json); this.setState({ data: json }) }) .catch((err) => { console.log('fetch request failed: ', err) } )
3
    fetch(url, {
        headers: {
            'Accept': 'application/json',
        },
    }).then((response) => response.json()
        .catch(err => {
            console.err(`'${err}' happened!`);
            return {};
        }))
        .then((json) => {
            console.log('parsed json: ', json);
            this.setState({ data: json })
        })
        .catch((err) => { console.log('fetch request failed: ', err) }
        )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.