Application Android et IOS pour l'amicale des élèves https://play.google.com/store/apps/details?id=fr.amicaleinsat.application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CacheProvider.tsx 819B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import React, { useState } from 'react';
  2. import {
  3. CacheContext,
  4. CacheContextType,
  5. CacheType,
  6. } from '../../context/cacheContext';
  7. type Props = {
  8. children: React.ReactChild;
  9. };
  10. export default function CacheProvider(props: Props) {
  11. const setCache = (newCache: CacheType) => {
  12. setCacheState((prevState) => ({
  13. ...prevState,
  14. cache: {
  15. ...prevState.cache,
  16. ...newCache,
  17. },
  18. }));
  19. };
  20. const resetCache = () => {
  21. setCacheState((prevState) => ({
  22. ...prevState,
  23. cache: undefined,
  24. }));
  25. };
  26. const [cacheState, setCacheState] = useState<CacheContextType>({
  27. cache: undefined,
  28. setCache: setCache,
  29. resetCache: resetCache,
  30. });
  31. return (
  32. <CacheContext.Provider value={cacheState}>
  33. {props.children}
  34. </CacheContext.Provider>
  35. );
  36. }