# code-block-pro/1.27.7/src/state/language.ts

Code Block Pro – Beautiful Syntax Highlighting, version 1.27.7. 41 lines.

- Page: https://pluginprobe.com/plugins/code-block-pro/1.27.7/code/src/state/language.ts
- Raw: https://pluginprobe.com/plugins/code-block-pro/1.27.7/raw/src/state/language.ts
- Modified: 2024-04-04T17:53:20+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/code-block-pro/1.27.7/code/src/state/language.ts#L10-L20`.

```typescript
import { create } from 'zustand';
import { devtools, persist } from 'zustand/middleware';
import { Lang } from '../types';

type LanguageType = {
    previousLanguage: Lang;
    setPreviousLanguage: (language: Lang) => void;
    recentLanguages: Lang[];
    addRecentLanguage: (language: Lang) => void;
};
export const useLanguageStore = create<LanguageType>()(
    persist(
        devtools(
            (set, get) => ({
                previousLanguage: 'javascript' as Lang,
                setPreviousLanguage(language: Lang) {
                    set({ previousLanguage: language });
                    get().addRecentLanguage(language);
                },
                recentLanguages: [] as Lang[],
                addRecentLanguage(language: Lang) {
                    // Limit to the last 5
                    set((state) => {
                        if (state.recentLanguages.includes(language)) {
                            return state;
                        }
                        return {
                            recentLanguages: [
                                ...(state.recentLanguages?.slice(-4) || []),
                                language,
                            ],
                        };
                    });
                },
            }),
            { name: 'Code Block Pro Language' },
        ),
        { name: 'code-block-pro-last-language' },
    ),
);

```
