Comments (9)
Thanks ! That was it ! 0.3 fixed the issue for me.
from fetch-hoc.
Thanks for the report - I'll look into it. Jump back to 0.1 in the mean time
from fetch-hoc.
@esphen Yeah already reverted to 0.1 and it works fine
from fetch-hoc.
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.
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.
Yes the problem seems to come from stateless components. I'm only using stateless component with fetch-hoc.
from fetch-hoc.
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.
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:
Object { loading: false, success: undefined, error: undefined }
Object { loading: true, success: undefined, error: undefined, response: undefined }
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.
I released 0.3.0 with the above change, try it out
from fetch-hoc.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fetch-hoc.