Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #159 from jamesplease/3.0.0
Browse files Browse the repository at this point in the history
3.0.0
  • Loading branch information
jamesplease authored Apr 25, 2018
2 parents a5ee7cf + 24546f2 commit 5eddd22
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 150 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

### v3.0.0 (2018/4/24)

> Although the changes in this release are technically breaking, they are unlikely to
> affect most users' code.
**Breaking Changes**

* When a request fails, the `data` from a request will no longer be set to `null`. This
allows you to control whether or not your UI continues to display the existing data.

* The `responseType` prop is now more forgiving. If the body cannot be parsed with
the `responseType` that you set, then `data` will be set to `null`.

### v2.0.4 (2018/4/20)

**Bug Fixes**
Expand Down
26 changes: 2 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,30 +364,8 @@ about the response, such as its status code.
</Fetch>
```
```jsx
// Some "enterprisey" endpoints return text stack traces anytime that they error. A function
// `responseType` can protect you against this.
<Fetch
url="/countries/2"
responseType={response => {
// Only parse as JSON when the request's code is not an error code, and it is
// not 204 No Content.
return response.ok && response.status !== 204 ? 'json' : 'text';
}}
transformData={countryName => {
return {
countryName
};
}}>
{({ data }) => {
if (data) {
return <div>{data.countryName}</div>;
}

return null;
}}
</Fetch>
```
If the response body cannot be parsed as the `responseType` that you specify, then `data` will
be set to `null`.
##### `requestName`
Expand Down
2 changes: 1 addition & 1 deletion examples/fetch-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"react": "^16.2.0",
"react-composer": "^4.1.0",
"react-dom": "^16.2.0",
"react-request": "^2.0.4",
"react-request": "^3.0.0",
"react-scripts": "1.1.0"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/lazy-read/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-request": "^2.0.4",
"react-request": "^3.0.0",
"react-scripts": "1.1.0"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/multiple-requests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"react": "^16.2.0",
"react-composer": "^4.1.0",
"react-dom": "^16.2.0",
"react-request": "^2.0.4",
"react-request": "^3.0.0",
"react-scripts": "1.1.0"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/request-deduplication/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-request": "^2.0.4",
"react-request": "^3.0.0",
"react-scripts": "1.1.0"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/response-caching/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-request": "^2.0.4",
"react-request": "^3.0.0",
"react-scripts": "1.1.0"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-read/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-request": "^2.0.4",
"react-request": "^3.0.0",
"react-scripts": "1.1.0"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/updating-a-resource/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-request": "^2.0.4",
"react-request": "^3.0.0",
"react-scripts": "1.1.0"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-request",
"version": "2.0.4",
"version": "3.0.0",
"description": "Declarative HTTP requests with React.",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down Expand Up @@ -83,7 +83,7 @@
"rollup-plugin-uglify": "^2.0.1"
},
"dependencies": {
"fetch-dedupe": "^2.1.0",
"fetch-dedupe": "^3.0.0",
"prop-types": "^15.6.0"
}
}
8 changes: 8 additions & 0 deletions src/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,14 @@ export class Fetch extends React.Component {

data = data ? this.props.transformData(data) : null;

// If we already have some data in state on error, then we continue to
// pass that data down. This prevents the data from being wiped when a
// request fails, which is generally not what people want.
// For more, see: GitHub Issue #154
if (error && this.state.data) {
data = this.state.data;
}

if (hittingNetwork) {
this.props.afterFetch({
url,
Expand Down
Loading

0 comments on commit 5eddd22

Please sign in to comment.