Comparing version 0.1.73 to 0.1.74
@@ -112,2 +112,3 @@ "use strict"; | ||
} | ||
return data; | ||
}); | ||
@@ -114,0 +115,0 @@ } |
{ | ||
"name": "use-http", | ||
"version": "0.1.73", | ||
"version": "0.1.74", | ||
"homepage": "https://codesandbox.io/embed/km04k9k9x5", | ||
@@ -23,3 +23,3 @@ "main": "dist/index.js", | ||
"@types/node": "^12.0.10", | ||
"@types/react": "^16.8.19", | ||
"@types/react": "16.8.21", | ||
"@types/react-dom": "^16.8.4", | ||
@@ -26,0 +26,0 @@ "jest": "^24.7.1", |
@@ -0,1 +1,4 @@ | ||
<a href="http://use-http.com"> | ||
<img src="https://github.com/alex-cory/use-http/raw/master/public/dog.png" /> | ||
</a> | ||
@@ -13,3 +16,3 @@ <p align="center"> | ||
</a> | ||
<a href="https://www.npmjs.com/package/use-http"> | ||
<a href="https://www.npmtrends.com/use-http"> | ||
<img src="https://img.shields.io/npm/dm/use-http.svg" /> | ||
@@ -23,5 +26,2 @@ </a> | ||
</a> | ||
<a href="https://codeclimate.com/github/alex-cory/use-http/maintainability"> | ||
<img src="https://api.codeclimate.com/v1/badges/1e6c1ff8921b0f5ff6b3/maintainability" /> | ||
</a> | ||
<a href="https://snyk.io/test/github/alex-cory/use-http?targetFile=package.json"> | ||
@@ -41,3 +41,6 @@ <img src="https://snyk.io/test/github/alex-cory/use-http/badge.svg?targetFile=package.json" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/alex-cory/use-http?targetFile=package.json" style="max-width:100%;"> | ||
<img align="right" src="https://media.giphy.com/media/fAFg3xESCJyw/giphy.gif" /> | ||
<a href="https://github.com/alex-cory/use-http"> | ||
<img align="right" src="https://media.giphy.com/media/fAFg3xESCJyw/giphy.gif" /> | ||
</a> | ||
<p> | ||
@@ -51,2 +54,5 @@ Need to fetch some data? Try this one out. It's an isomorphic fetch hook. That means it works with SSR (server side rendering). | ||
**⚠️ Please view the [Main Documentation](http://use-http.com)** | ||
Features | ||
@@ -61,6 +67,2 @@ --------- | ||
### Examples | ||
- <a target="_blank" rel="noopener noreferrer" href='https://codesandbox.io/s/usefetch-in-nextjs-nn9fm'>Example - Next.js</a> | ||
- <a target="_blank" rel="noopener noreferrer" href='https://codesandbox.io/embed/km04k9k9x5'>Examples - create-react-app</a> | ||
Installation | ||
@@ -75,27 +77,43 @@ ------------ | ||
----- | ||
<details> | ||
<summary><b>⚠️ Examples <sup>click me</sup></b></summary> | ||
<ul> | ||
<li><a target="_blank" rel="noopener noreferrer" href='https://codesandbox.io/s/usefetch-in-nextjs-nn9fm'>useFetch + Next.js</a></li> | ||
<li><a target="_blank" rel="noopener noreferrer" href='https://codesandbox.io/embed/km04k9k9x5'>useFetch + create-react-app</a></li> | ||
<li><a target="_blank" rel="noopener noreferrer" href='https://codesandbox.io/s/useget-with-provider-c78w2'>useGet + < Provider /></a></li> | ||
</ul> | ||
</details> | ||
#### Basic Usage | ||
```jsx | ||
```js | ||
import useFetch from 'use-http' | ||
function Todos() { | ||
const options = { // accepts all `fetch` options | ||
onMount: true // will fire on componentDidMount | ||
const [todos, setTodos] = useState([]) | ||
const request = useFetch('https://example.com') | ||
useEffect(() => { | ||
initializeTodos() | ||
}, []) | ||
async function initializeTodos() { | ||
const initialTodos = await request.get('/todos') | ||
setTodos(initialTodos) | ||
} | ||
const todos = useFetch('https://example.com/todos', options) | ||
function addTodo() { | ||
todos.post({ | ||
async function addTodo() { | ||
const newTodo = await request.post('/todos', { | ||
title: 'no way', | ||
}) | ||
setTodos(oldTodos => [...oldTodos, newTodo]) | ||
} | ||
if (todos.error) return 'Error!' | ||
if (todos.loading) return 'Loading...' | ||
return ( | ||
<> | ||
<button onClick={addTodo}>Add Todo</button> | ||
{todos.data.map(todo => ( | ||
{request.error && 'Error!'} | ||
{request.loading && 'Loading...'} | ||
{todos.length > 0 && todos.map(todo => ( | ||
<div key={todo.id}>{todo.title}</div> | ||
@@ -107,2 +125,3 @@ )} | ||
``` | ||
#### Destructured | ||
@@ -116,2 +135,3 @@ ```jsx | ||
#### Relative routes | ||
⚠️ `baseUrl` is no longer supported, it is now only `url` | ||
```jsx | ||
@@ -118,0 +138,0 @@ var request = useFetch({ url: 'https://example.com' }) |
Sorry, the diff of this file is not supported yet
69327
753
475