feat: removed react example

This commit is contained in:
arthurfiorette 2023-05-17 19:29:05 -03:00
parent f29dc4076c
commit d72b122ede
No known key found for this signature in database
GPG Key ID: 9D190CD53C53C555
4 changed files with 7 additions and 77 deletions

7
examples/react/README.md Normal file
View File

@ -0,0 +1,7 @@
# React example.
There used to be a simple react example with contexts, but as I mainly work with React on
the frontend, I decided to create another library to solve this usage in a beautiful,
faster and minimalistic way.
See [**Axios Cache Hooks**](https://tinylibs.js.org/packages/axios-cache-hooks/)

View File

@ -1,38 +0,0 @@
/* eslint-disable */
import { useState } from 'react';
import { useAxios } from './axios-context';
export const App = () => {
// You can use react context, as exemplified here
// but you can also just export the AxiosCacheInstance
// from a file and use it directly. Happy coding :)
const axios = useAxios();
const [{ data, error, loading }, setResponse] = useState({
data: [],
loading: true,
error: null
});
useEffect(() => {
axios.get('https://jsonplaceholder.typicode.com/users').then(
({ data }) => setResponse({ data, loading: false, error: null }),
(error) => setResponse({ data: [], loading: false, error })
);
}, []);
if (loading) {
return <div>Loading...</div>;
}
if (error) {
return <div>Error: {error.message}</div>;
}
return (
<div>
<div>{data}</div>
</div>
);
};

View File

@ -1,27 +0,0 @@
/* eslint-disable */
/*
* Replace ../../src with axios-cache-interceptor
*/
import Axios from 'axios';
import { createContext, useContext, useState } from 'react';
import { setupCache } from '../../src'; // axios-cache-interceptor
/** @type {import('react').Context<import('../../src').AxiosCacheInstance>} */
const AxiosContext = createContext(null);
export const useAxios = () => useContext(AxiosContext);
export const AxiosProvider = ({ children }) => {
const [axios] = useState(
setupCache(
// Custom instance to prevent conflict with other pieces of code
Axios.create(),
// cache config
{}
)
);
return <AxiosContext.Provider value={axios}>{children}</AxiosContext.Provider>;
};

View File

@ -1,12 +0,0 @@
/* eslint-disable */
import ReactDOM from 'react-dom';
import { App } from './app';
import { AxiosProvider } from './axios-context';
ReactDOM.render(
<AxiosProvider>
<App />
</AxiosProvider>,
document.getElementById('root')
);