Coder Social home page Coder Social logo

Update to 0.2 breaks about fetch-hoc HOT 9 CLOSED

moimael avatar moimael commented on June 22, 2024
Update to 0.2 breaks

from fetch-hoc.

Comments (9)

moimael avatar moimael commented on June 22, 2024 1

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

from fetch-hoc.

eliihen avatar eliihen commented on June 22, 2024

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

from fetch-hoc.

moimael avatar moimael commented on June 22, 2024

@esphen Yeah already reverted to 0.1 and it works fine

from fetch-hoc.

eliihen avatar eliihen commented on June 22, 2024

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?

from fetch-hoc.

bidanjun avatar bidanjun commented on June 22, 2024

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.

from fetch-hoc.

moimael avatar moimael commented on June 22, 2024

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

from fetch-hoc.

eliihen avatar eliihen commented on June 22, 2024

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?

from fetch-hoc.

eliihen avatar eliihen commented on June 22, 2024

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.

from fetch-hoc.

eliihen avatar eliihen commented on June 22, 2024

I released 0.3.0 with the above change, try it out

from fetch-hoc.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.