1.8.0 • Published 2 years ago

react-cache-state v1.8.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

React Cache State

This component adding cache for you app

How Work?

Add Cache Provider in App Initail

import React from "react";

export default function Index() {
  return (
    <CacheProvider>
      <App />
    </CacheProvider>
  );
}

After use hooks for using cache

import React from "react";

export default function Index() {
  const getData = async () => {
    const res = await fetch(api);
    return await res.json();
  };
  const [data, triggerData] = useCache("key", getData);
  return (
    <div>
      {data.map((x) => (
        <div>{x}</div>
      ))}
      <button onClick={triggerData}>update data</button>
      {
        //  or
      }
      <button
        onClick={() => {
          triggerData(data);
        }}
      >
        updatedata
      </button>
    </div>
  );
}

When triggerData work two form

1.- When the function is executed without passing parameters it is updated with the function that is sent to useCache 2.- When passing parameters you can send data or a function that returns the data you want to update

1.8.0

2 years ago

1.7.9

2 years ago

1.7.8

2 years ago

1.7.7

2 years ago

1.7.6

2 years ago

1.7.5

2 years ago

1.7.4

2 years ago

1.7.3

2 years ago

1.7.1

2 years ago

1.7.0

2 years ago

1.6.9

2 years ago

1.6.8

2 years ago

1.6.7

2 years ago

1.6.6

2 years ago

1.6.5

2 years ago

1.6.4

2 years ago

1.6.3

2 years ago

1.6.2

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago