-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from sheaivey/withAxios
@achepukov thanks for your initial work and input for a more robust `withAxios(options)(ComponentToBeWrapped)` HoC. I have gone ahead and published the react-axios `v2.0.2` with the changes from this branch.
- Loading branch information
Showing
11 changed files
with
239 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"presets" : [ | ||
"./tools/babelPreset", | ||
"stage-2", | ||
"react" | ||
], | ||
"env": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { withAxios } from 'react-axios' | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
|
||
class App extends React.Component { | ||
render() { | ||
return ( | ||
<div> | ||
<code> | ||
<h2>Basic withAxios HoC</h2> | ||
<DemoComponentHoC /> | ||
|
||
<h2>Custom props withAxios HoC</h2> | ||
<DemoComponentHoC customProp={'Custom Prop'} /> | ||
|
||
<h2>Overloading withAxios HoC config options</h2> | ||
<DemoComponentHoC options={{ method: 'post', url: '/api/overloaded' }} /> | ||
|
||
<h2>Children withAxios HoC</h2> | ||
<DemoComponentHoC><div className="success">children</div></DemoComponentHoC> | ||
</code> | ||
</div> | ||
) | ||
} | ||
} | ||
/* eslint react/prop-types: 0 */ | ||
class DemoComponent extends React.Component { | ||
render() { | ||
const { error, response, isLoading, children, customProp, onRendered } = this.props | ||
if(error) { | ||
return (<div>Something bad happened: {error.message}</div>) | ||
} else if(isLoading) { | ||
return (<div className="loader"></div>) | ||
} else if(response !== null) { | ||
return (<div>{response.data.message} {customProp} {children}</div>) | ||
} | ||
return customProp || null | ||
} | ||
} | ||
|
||
const DemoComponentHoC = withAxios({ | ||
method:'get', | ||
url: '/api/request', | ||
})(DemoComponent) | ||
|
||
ReactDOM.render( | ||
<App />, | ||
document.getElementById('app') | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Examples</title> | ||
<link href="/style.css" rel="stylesheet"/> | ||
</head> | ||
<body> | ||
<h1 class="breadcrumbs"><a href="/">React Axios Examples</a> / withAxios</h1> | ||
<div id="app"></div> | ||
<script src="/__build__/shared.js"></script> | ||
<script src="/__build__/withAxios.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.