Skip to content

Instantly share code, notes, and snippets.

@adrianhajdin
adrianhajdin / StateContext.js
Last active April 9, 2024 15:49
Build and Deploy a Modern Full Stack ECommerce Application with Stripe
import React, { createContext, useContext, useState, useEffect } from 'react';
import { toast } from 'react-hot-toast';
const Context = createContext();
export const StateContext = ({ children }) => {
const getLocalStorage = (name) => {
if (typeof window !== 'undefined') {
const storage = localStorage.getItem(name);