How to store single cache data in ReactJS ? Last Updated : 02 Nov, 2023 Comments Improve Suggest changes Like Article Like Report Storing Data in a cache is an important task in web applications. We can cache some data into the browser and use it in our application whenever needed. Caching is a technique that helps us to store a copy of a given resource in our browser and serve it back when requested. PrerequisitesReact JSCacheStorageApproachTo store single cache data in React JS we will use the Windows cache that helps to access the cache stored in the browser window. Define a function that accesses named data in the cache storage and then puts the custom data the user needs to store in the browser. Steps to create React ApplicationStep 1: Create a React application using the following command: npx create-react-app foldernameStep 2: After creating your project folder i.e. folder name, move to it using the following command: cd foldernameProject Structure:Project StructureExample: Created a addDataIntoCache function which takes the user data and store into the browser cache. When we click on the button, the function is triggered and data gets stored into the cache, and we see an alert popup. App.js // Filename - App.js import * as React from "react"; export default function App() { // Function to add our give data into cache const addDataIntoCache = (cacheName, url, response) => { // Converting our response into Actual Response form const data = new Response(JSON.stringify(response)); console.log(data); if ("caches" in window) { // Opening given cache and putting our data into it caches.open(cacheName).then((cache) => { cache.put(url, data); alert("Data Added into cache!"); }); } }; return ( <div style={{ height: 500, width: "80%", textAlign: "center", margin: "auto", }} > <h1 style={{ color: "green" }}> GeeksforGeeks </h1> <h4>Store data into cache in React JS</h4> <button onClick={() => addDataIntoCache( "MyCache", "https://www.geeksforgeeks.org/", "SampleData" ) } > Add Data Into Cache </button> </div> ); } Steps to Run Application: Run the application using the following command from the root directory of the project: npm startOutput: Now open your browser and go to http://localhost:3000/, you will see the following output: Comment More infoAdvertise with us Next Article How to store single cache data in ReactJS ? gouravhammad Follow Improve Article Tags : JavaScript Web Technologies ReactJS React-Questions Similar Reads How to get single cache data in ReactJS ? We can use cache storage using window cache and in React JS to get single cache data. We can get single cache data from the browser and use it in our application whenever needed. Caching is a technique that helps us to store a copy of a given resource in our browser and serve it back when requested. 2 min read How to Create Store in React Redux ? React Redux is a JavaScript library that is used to create and maintain state in React Applications efficiently. Here React Redux solves the problem by creating a redux store that stores the state and provides methods to use the state inside any component directly or to manipulate the state in a def 4 min read How to delete specific cache data in ReactJS ? In React, we can access all cache data from the browser and delete specific cache data from the browser as per the user's requirement whenever needed using the Cache Storage of the browser. Caching is a technique that helps us to store a copy of a given resource in our browser and serve it back when 2 min read How to Access Cache Data in Node.js ? Caching is an essential technique in software development that helps improve application performance and scalability by temporarily storing frequently accessed data. In Node.js, caching can significantly reduce database load, minimize API response times, and optimize resource utilization. This artic 5 min read How to Set Cookie in ReactJS ? Cookies in React are used to set value in a key-value form which can be set in browser storage and used further for identifying the current user. The following example shows how to set the cookie in the ReactJS application, here we have taken the custom-cookie as key, which is set in the cookie with 3 min read How to cache JSON data in Redis with NodeJS? To cache JSON data in Redis with Node.js, you can use the redis npm package along with JSON serialization and deserialization. Redis, an open-source, in-memory data store, is commonly used as a caching solution due to its high performance and flexibility. In this tutorial, we'll explore how to cache 3 min read How to get multiple cache data in ReactJS ? We can use the following approach in ReactJS to get multiple cache data. We can get multiple cache data from the browser and use them in our application whenever needed. Caching is a technique that helps us to store a copy of a given resource in our browser and serve it back when requested.Prerequis 2 min read How to get complete cache data in ReactJS? In React, we can get all cache data from the browser and use it in our application whenever needed. Caching is a technique that helps us to store a copy of a given resource in our browser and serve it back when requested.PrerequisitesReact JSCacheStorageApproachTo get all cache data in React JS defi 2 min read How to clear complete cache data in ReactJS ? Caching is a technique that helps us to store a copy of a given resource in our browser and serve it back when requested. There is no direct option to clear the cache as it is a client-side feature managed by the browser. To clear the complete cache in React JS we can use JavaScipt's cache storage A 2 min read How to delete multiple cache data in ReactJS ? In React, we can access all cache data from the browser and modify it as required whenever needed using the Cache Storage of the browser. Caching is a technique that helps us to store a copy of a given resource in our browser and serve it back when requested. Prerequisites:NPM & Node.jsReact JSC 2 min read Like