Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
23 changes: 23 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# React-Data-Fetching Examples

### Declarative data fetching for React

`react-data-fetching` provides a very intuitive way to perform any REST API call without hassle, through a single React component. It also helps you take care of timeouts, loading states, errors handling, data saving, uploading/downloading progress, etc. Fetching data while letting the user know what's going on has never been that easy!

The package is really lightweight (~6 kB gzipped) and has been built from the ground up with universal apps in mind: you can use it wherever React is rendering - meaning it works seamlessly with React (web) & React Native!


## Installation

Using [Yarn](https://yarnpkg.com/):

```shell
$ yarn install
$ yarn run example
```

Then visit `http://localhost:8080/`.

## About

`react-data-fetching` is currently developed and maintained by yours truly, [@Charles_Mangwa](https://twitter.com/Charles_Mangwa). Feel free to get in touch if you want to contribute!
57 changes: 57 additions & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "react-data-fetching-example",
"scripts": {
"example":
"webpack-dev-server --config ./webpack.config.js --mode development"
},
"babel": {
"presets": [
[
"env",
{
"loose": true
}
],
"stage-1",
"react",
"flow"
]
},
"peerDependencies": {
"react": ">=15 || ^16"
},
"dependencies": {
"babel-core": "^6.26.3",
"babel-polyfill": "^6.26.0",
"babel-runtime": "^6.26.0",
"invariant": "^2.2.2",
"prop-types": "^15.6.0",
"react-dom": "^16.4.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-eslint": "^8.0.2",
"babel-loader": "^7.1.4",
"babel-plugin-dev-expression": "^0.2.1",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.10",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"babel-preset-flow": "^6.23.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-1": "^6.24.1",
"coveralls": "^3.0.0",
"eslint": "^4.12.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-babel": "^4.1.2",
"eslint-plugin-flowtype": "^2.39.1",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-react": "7.6.0",
"flow-bin": "0.63.1",
"react": "^16.2.0",
"webpack": "^4.12.0",
"webpack-cli": "^3.0.3",
"webpack-dev-server": "^3.1.4"
}
}
Binary file added examples/public/favicon.ico
Binary file not shown.
10 changes: 10 additions & 0 deletions examples/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>The Minimal React Webpack Babel Setup</title>
</head>
<body>
<div id="app"></div>
<script src="/bundle.js"></script>
</body>
</html>
33 changes: 33 additions & 0 deletions examples/src/Basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { Component } from "react"
import Fetch from "../../modules/Fetch"

require("babel-polyfill")

const Loader = () => "Loading..."

class App extends Component {
render() {
return (
<div className="App">
<header className="App-header">
<h1 className="App-title">React-Data-Fetching Basic Example</h1>
</header>
<Fetch
loader={<Loader />} // Replace this with your lovely handcrafted loader
url="https://api.github.com/users/octocat"
>
{({ data, error }) => error
? <div>Fetch failed</div>
: (
<div>
<h3>Username</h3>
<p>{data.name}</p>
</div>
)}
</Fetch>
</div>
)
}
}

export default App
117 changes: 117 additions & 0 deletions examples/src/FetchDataExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import React, { Component } from "react"
import Fetch from "../../modules/FetchData"

require("babel-polyfill")

const fakeFetch = () => {
return new Promise((res, rej) => {
setTimeout(() => {
res({
name: "User A"
})
}, 1000)
})
}

class App extends Component {
render() {
return (
<div className="App">
<header className="App-header">
<h1 className="App-title">React-Data-Fetching &ltFetchData /&gt Example</h1>
<h3>You can use an url or a fetch function</h3>
</header>
<div style={{ float: "left", width: "30%" }}>
<h3>Using fetch prop</h3>
<Fetch
fetch={fakeFetch}
subscribe={{
onWillMount: () => console.log("Component will mount"),
onDidMount: () => console.log("Component has mounted"),
onSuccess: (data) => console.log("Data has been updated!", data)
}}
>
{(props) => {
return (
<div>
{props.data.cata({
SUCCESS: _data => (
<div>
<h3>Username</h3>
<p>{_data.name}</p>
</div>
),
FAILURE: error => <div>Something went wrong!</div>,
LOADING: () => <div>Loading...</div>,
INIT: () => <div>Nothing Loaded Yet.</div>
})}
<button onClick={props.run}>Refetch</button>
</div>
)}}
</Fetch>
</div>
<div style={{ float: "left", width: "30%" }}>
<h3>Using fetch and lazy option</h3>
<Fetch
fetch={fakeFetch}
subscribe={{
onWillMount: () => console.log("Component will mount"),
onDidMount: () => console.log("Component has mounted"),
onSuccess: (data) => console.log("Data has been updated!", data)
}}
options={{ lazy: true }}
>
{(props) => {
return (
<div>
{props.data.cata({
SUCCESS: _data => (
<div>
<h3>Username</h3>
<p>{_data.name}</p>
</div>
),
FAILURE: error => <div>Something went wrong!</div>,
LOADING: () => <div>Loading...</div>,
INIT: () => <div>Nothing Loaded Yet.</div>
})}
<button onClick={props.run}>Refetch</button>
</div>
)}}
</Fetch>
</div>
<div style={{ float: "left", width: "30%" }}>
<h3>Using url prop</h3>
<Fetch
url="https://api.github.com/users/octocat"
subscribe={{
onWillMount: () => console.log("Component will mount"),
onDidMount: () => console.log("Component has mounted"),
onSuccess: (data) => console.log("Data has been updated!", data)
}}
>
{(props) => {
return (
<div>
{props.data.cata({
SUCCESS: _data => (
<div>
<h3>Username</h3>
<p>{_data.name}</p>
</div>
),
FAILURE: error => <div>Something went wrong!</div>,
LOADING: () => <div>Loading...</div>,
INIT: () => <div>Nothing Loaded Yet.</div>
})}
<button onClick={props.run}>Refetch Url</button>
</div>
)}}
</Fetch>
</div>
</div>
)
}
}

export default App
5 changes: 5 additions & 0 deletions examples/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react'
import ReactDOM from 'react-dom'
import FetchDataExample from './FetchDataExample'

ReactDOM.render(<FetchDataExample />, document.getElementById('app'))
32 changes: 32 additions & 0 deletions examples/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var path = require("path");

module.exports = {
entry: ["./src/index.js"],
output: {
path: __dirname + "/public",
publicPath: "/",
filename: "bundle.js"
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
options: {
presets: ["stage-1", "react", "flow"]
}
}
]
}
]
},
resolve: {
extensions: ["*", ".js", ".jsx"]
},
devServer: {
contentBase: "./public"
}
};
Loading