{"size": 1198, "ext": "js", "max_stars_repo_path": "src/contexts/CounterContext.js", "max_stars_repo_name": "DavKub/crystal-clicker", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/contexts/CounterContext.js", "max_issues_repo_name": "DavKub/crystal-clicker", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/contexts/CounterContext.js", "max_forks_repo_name": "DavKub/crystal-clicker", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.2195121951, "max_line_length": 78, "alphanum_fraction": 0.6227045075}
import React, { createContext, useContext, useEffect, useState } from 'react';
import { KoboldContext } from './KoboldContext';

export const CounterContext = createContext();

export const CounterContextProvider = ({ children }) => {
    const { koboldTotalCrystalYield } = useContext(KoboldContext);

    const [crystalCount, setCrystalCount] = useState(
        JSON.parse(localStorage.getItem('crystalCount')) || 0
    );

    const [crystalsLifetime, setCrystalsLifetime] = useState(
        JSON.parse(localStorage.getItem('crystalsLifetime')) || 0
    );

    useEffect(() => {
        const crystalGenerator = setTimeout(() => {
            setCrystalCount(crystalCount + koboldTotalCrystalYield);
            setCrystalsLifetime(crystalsLifetime + koboldTotalCrystalYield);
        }, 1500);

        return () => clearTimeout(crystalGenerator);
    });

    return (
        <CounterContext.Provider
            value={{
                crystalCount,
                setCrystalCount,
                crystalsLifetime,
                setCrystalsLifetime,
            }}
        >
            {children}
        </CounterContext.Provider>
    );
};

export default CounterContextProvider;
