*** title: How to Implement Feature Flags in SvelteKit slug: /guides/implement-feature-flags-in-sveltekit description: How to use Unleash feature flags with SvelteKit. keywords: 'implement, feature, flags, feature flags, unleash' 'og:site\_name': Unleash Documentation 'og:title': How to Implement Feature Flags in SvelteKit max-toc-depth: 3 ---------------- Hello and welcome to another tutorial. This is about adding feature flags to an app made with [SvelteKit](https://kit.svelte.dev/), [Unleash](https://www.getunleash.io/) and the official [Unleash Svelte SDK](/sdks/svelte). We'll make a paired-down habits app to keep track of your new year's resolutions. The feature flag will be used to change the number of habits a user can add. While this is not meant to be a complete product, we can leverage feature flags using a full stack framework like Next.js or SvelteKit. The completed code for this implementation is available in [a Github repository](https://github.com/alvinometric/unleash-sveltekit). ## 1. Setup Create a skeleton SvelteKit project named "habits". ```sh npm create svelte@latest habits ``` We'll need a few more dependencies. You can install these in one command below: ```sh npm i date-fns @unleash/proxy-client-svelte ``` ## 2. Create a basic habits app We'll use Svelte stores to keep track of a global array of habits. For the sake of simplicity, we won't store these habits anywhere yet (feel free to add localStorage or a database). Our basic habit app will only consist of 3 files. First, a global store that will contain our habits and their completion dates. Just JavaScript, no Svelte yet. ```js // src/lib/stores.js export const habitStore = writable([ { id: 1, name: "Walk 10k steps", completedDays: [], }, ]); ``` Then, we'll create an `App.svelte` file for our main logic. ```svelte {#each dates as date} {/each} {#each $habitStore as habit} {/each}
Habit{format(date, 'MMM do')}
``` Next, update the `+page.svelte` file (our index route) to include our app. ```svelte ``` To complete the basic setup of the app, add a component for each habit that be checked on and off using this code snippet: ```svelte {habit.name} {#each dates as date} toggleDay(date)} checked={habit.completedDays.includes(date)} /> {format(date, 'MMM do')} {/each} ``` Now we have a fully functioning Svelte app in all its glory! Essentially, it's a table with checkboxes. ![Our habits app, a table with each habit as a row](https://files.buildwithfern.com/unleash.docs.buildwithfern.com/4a5f203e24ac6fc1ba89b920ce8812858f966f15bf13610f7090f739cb56bdd6/assets/sveltekit-tutorial-browser.png) ## 3. Add habits and premium features We have the basics of the app set up, but we could make it more user-friendly. Let's add some more functionality: * Add the ability for users create their own habits * Limit the number of habits a user can create to a certain amount so we can turn this into a commercial product. Let's do all of this in another component named `AddHabit.svelte`. ```svelte

❌ Maximum Habits Reached

You can only have up to {maxHabits} on the free tier. Purchase a premium version to unlock more.

``` What's happening here? A few things: * An input and a button to add new habits to the store, until an arbitrary limit is reached * A `maxHabits` prop is used to determine that limit * When this maximum limit is reached, a modal dialog opens * We reset the form after submission to clear the input