Skip to content

Commit

Permalink
Provider para historial de productos
Browse files Browse the repository at this point in the history
  • Loading branch information
hendaniel committed Sep 7, 2020
1 parent 34ce37c commit 814877a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/providers/HistoryProvider.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { useState, useEffect } from "react";
import { getHistory } from "../services/userService";

export const HistoryContext = React.createContext();

const HistoryProvider = ({ children }) => {
const [products, setProducts] = useState({});

const [productResponse, setProductResponse] = useState({});

useEffect(() => {
getHistory().then((products) => {
setProducts(products);
});
}, [productResponse]);

return (
<HistoryContext.Provider value={{ products, setProductResponse }}>
{children}
</HistoryContext.Provider>
);
};

export default HistoryProvider;
11 changes: 11 additions & 0 deletions src/services/userService.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,14 @@ export const addPoints = (coins) => {
})
.then((response) => response.json());
};

export const getHistory = () => {
return fetch(API.HISTORY, { headers })
.then((response) => {
if (!response.ok) {
throw Error(response.statusText);
}
return response;
})
.then((response) => response.json());
};

0 comments on commit 814877a

Please sign in to comment.