From d72b122ede6c8e583cd9fd059c5736f2277a6ff8 Mon Sep 17 00:00:00 2001 From: arthurfiorette Date: Wed, 17 May 2023 19:29:05 -0300 Subject: [PATCH] feat: removed react example --- examples/react/README.md | 7 ++++++ examples/react/app.js | 38 --------------------------------- examples/react/axios-context.js | 27 ----------------------- examples/react/index.js | 12 ----------- 4 files changed, 7 insertions(+), 77 deletions(-) create mode 100644 examples/react/README.md delete mode 100644 examples/react/app.js delete mode 100644 examples/react/axios-context.js delete mode 100644 examples/react/index.js diff --git a/examples/react/README.md b/examples/react/README.md new file mode 100644 index 0000000..8cef818 --- /dev/null +++ b/examples/react/README.md @@ -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/) diff --git a/examples/react/app.js b/examples/react/app.js deleted file mode 100644 index 700ea0c..0000000 --- a/examples/react/app.js +++ /dev/null @@ -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
Loading...
; - } - - if (error) { - return
Error: {error.message}
; - } - - return ( -
-
{data}
-
- ); -}; diff --git a/examples/react/axios-context.js b/examples/react/axios-context.js deleted file mode 100644 index e49235a..0000000 --- a/examples/react/axios-context.js +++ /dev/null @@ -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} */ -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 {children}; -}; diff --git a/examples/react/index.js b/examples/react/index.js deleted file mode 100644 index f32d5bb..0000000 --- a/examples/react/index.js +++ /dev/null @@ -1,12 +0,0 @@ -/* eslint-disable */ - -import ReactDOM from 'react-dom'; -import { App } from './app'; -import { AxiosProvider } from './axios-context'; - -ReactDOM.render( - - - , - document.getElementById('root') -);