Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 0.2 breaks #3

Closed
moimael opened this issue Jul 10, 2017 · 9 comments
Closed

Update to 0.2 breaks #3

moimael opened this issue Jul 10, 2017 · 9 comments

Comments

@moimael
Copy link

moimael commented Jul 10, 2017

After updating to 0.2, none of my requests are fired anymore, loading prop is always false and data always undefined.

@eliihen
Copy link
Owner

eliihen commented Jul 10, 2017

Thanks for the report - I'll look into it. Jump back to 0.1 in the mean time

@moimael
Copy link
Author

moimael commented Jul 10, 2017

@esphen Yeah already reverted to 0.1 and it works fine

@eliihen
Copy link
Owner

eliihen commented Jul 10, 2017

I tried to reproduce this today, but no luck. 0.2 seems to work fine in my tests. See this repo.

Can you please provide a minimal reproduction repo?

@bidanjun
Copy link

maybe here:{this.props.data ? JSON.stringify(this.props.data, null, 2) : 'no error' }
i use stateless component,and if simplely use {this.props.data},it will crash,and data is undefine.

@moimael
Copy link
Author

moimael commented Aug 7, 2017

Yes the problem seems to come from stateless components. I'm only using stateless component with fetch-hoc.

@eliihen
Copy link
Owner

eliihen commented Aug 7, 2017

Guys, rendering in a stateless component works fine for me.

import React from 'react';
import ReactDOM from 'react-dom';
import fetch from 'fetch-hoc';
import App from './App';

let FooComponent = props => {
  if (props.error) {
    return <div className="error">An error occured! {props.error.toString()}</div>;
  }
  if (props.loading) {
    return <div className="loading">Loading...</div>;
  }

  return (
    <code><pre>
      {JSON.stringify(props.data, null, 2)}
    </pre></code>
  );
}

FooComponent = fetch('http://httpbin.org/get')(FooComponent);

ReactDOM.render(<FooComponent />, document.getElementById('root'));

Can you please post a minimal reproducible case? A gist or something?

@eliihen
Copy link
Owner

eliihen commented Aug 7, 2017

I did some hacking, and may have an idea what your issue is. There was a change in the loading prop in 0.2.0 which changed its initial state to false. That change was not documented, that's my bad. I'll add it to the changelog.

Here's the loading states as present:

  1. Object { loading: false, success: undefined, error: undefined }
  2. Object { loading: true, success: undefined, error: undefined, response: undefined }
  3. Object { loading: false, success: true, error: undefined, response: Response, data: {…} }

My theory is that you're throwing on step 1 because data is not yet assigned. Is this correct?

The reasoning behind changing step 1 to be loading=false is because it's has not actually started fetching yet, and if you pass a function like fetch(props => props.url || null), that should not enter a loading state if props.url is not defined.

I realize this makes the API harder to use, so I'll look into calculating initial loading state based on what is passed to fetch(). I think that is the most correct solution here.

@eliihen
Copy link
Owner

eliihen commented Aug 7, 2017

I released 0.3.0 with the above change, try it out

@eliihen eliihen closed this as completed Aug 7, 2017
@moimael
Copy link
Author

moimael commented Aug 8, 2017

Thanks ! That was it ! 0.3 fixed the issue for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants