jamesplease / react-request

Declarative HTTP requests for React
MIT License
362 stars 21 forks source link

Redundant `render` run with outdated state #196

Open edoroshenko opened 6 years ago

edoroshenko commented 6 years ago

If I render the same Fetch with new url, first I get it's children rendered with previous state (old url, old data, etc.) It looks like the problem is known: https://github.com/jamesplease/react-request/blob/eca89d5fe79bd546a0641b6443415b722e3f6ec3/src/fetch.js#L107 It feels that it would be simple to fix it by updating Fetch state in componentWillReceiveProps hook. @jamesplease what's your opinion?

jamesplease commented 6 years ago

Thanks for the issue @edoroshenko !

It feels that it would be simple to fix it by...

I sometimes think something will be simple about this library, and then it surprises me. It's a real monster, honestly.

I'm open to using cWRP. In fact, it used to work that way. If you'd like to revert it, go ahead and make a PR, but you'll need to dodge some of the bugs that I fixed by making the swap.

If you decide to take this on, referencing this PR and this issue may be useful to you.

Good luck!

edoroshenko commented 6 years ago

Hi @jamesplease thanks for the details, they would be definitely helpful!

bghveding commented 6 years ago

Just wanted to mention that componentWillReceiveProps was deprecated in React 16.3 https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops