next js cookie

Step 1: Install the js-cookie library using the following command:

npm install js-cookie

Step 2: Import the js-cookie library in your Next.js component or page file:

import Cookies from 'js-cookie';

Step 3: Set a cookie using the set method. Provide a name, value, and optional configuration options:

Cookies.set('myCookie', 'cookieValue', { expires: 7 });

Step 4: Retrieve the value of a cookie using the get method:

const cookieValue = Cookies.get('myCookie');

Step 5: Update the value of a cookie using the set method:

Cookies.set('myCookie', 'newCookieValue');

Step 6: Delete a cookie using the remove method:

Cookies.remove('myCookie');

Note: Ensure that you have appropriate error handling and validation in your code to handle scenarios where cookies may not be set or retrieved successfully.