console.time("counter");
for (let i = 0; i < 1000000000; i++) {}
console.timeEnd("counter");counter: 933.401ms
| // persisting Context of theme | |
| import React from 'react'; | |
| import { useState, useEffect, useContext } from 'react'; | |
| import { usePersist } from '../hooks'; | |
| import { themeType } from '../types'; | |
| export interface IThemeProviderProps { | |
| theme: themeType; | |
| themeLoaded: boolean; |
| import { useState, useEffect } from 'react'; | |
| export const usePersist = (key: string, initialValue: any) => { | |
| const [value, setValue] = useState(() => { | |
| const storedValue = localStorage.getItem(key); | |
| return storedValue ? JSON.parse(storedValue) : initialValue; | |
| } | |
| ); | |
| useEffect(() => { |