Advertisement
fabiobiondi

React Pro - Real World App - Ch8. 09 - Barrel File

Mar 19th, 2023
1,245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // src/pages/cms/products/CMSProductsPage.tsx
  2.  
  3. import { useProductsService } from '@/services/products';
  4.  
  5. export function CMSProductsPage() {
  6.   const { state, actions } = useProductsService();
  7.  
  8.   async function getProductsHandler() {
  9.     actions.getProducts()
  10.   }
  11.  
  12.   return (
  13.     <div>
  14.       <h1 className="title">CMS</h1>
  15.  
  16.       Pagina Prodotti
  17.  
  18.       <hr className="my-8"/>
  19.  
  20.       {state.pending && <div>loading...</div>}
  21.       {state.error && <div>error!!!!</div>}
  22.  
  23.       <button className="btn primary" onClick={getProductsHandler}>GET</button>
  24.  
  25.       <pre>{JSON.stringify(state, null, 2)}</pre>
  26.     </div>
  27.   )
  28. }
  29.  
  30.  
  31. // =============================
  32. // services/products/index.ts
  33. export { useProductsService } from './useProductsService';
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement