Skip to content

Instantly share code, notes, and snippets.

@kevinmungai
Last active July 25, 2023 03:02
Show Gist options
  • Save kevinmungai/5787bd386321f98d70777b9bf1852cd8 to your computer and use it in GitHub Desktop.
Save kevinmungai/5787bd386321f98d70777b9bf1852cd8 to your computer and use it in GitHub Desktop.

_layout.svelte

<script lang="ts">

import { onMount, setContext } from "svelte";
import { firebaseStore } from "../stores/firebase_store";
import {Child} from "../components/Child.svelte";

setContext("firebaseStore", firebaseStore);


onMount(async () => {

const module = await import("firebase/app");  
 await import("firebase/auth");  
 await import("firebase/analytics");

const firebase = module.default;

const firebaseConfig = {  
 apiKey: "*",  
 authDomain: "*",  
 projectId: "",  
 storageBucket: "",  
 messagingSenderId: "",  
 appId: "",  
 measurementId: "",  
};  
 firebase.initializeApp(firebaseConfig);  
 firebase.analytics();
 
 $firebaseStore = firebase;

});

</script>

<div>

  <slot/>

 <Child/>

</div>

Child.svelte

<script lang="ts>

  import { onMount, getContext } from "svelte";
  
  let firebaseStore: any = getContext("firebaseStore");
  $: firebase = $firebaseStore;

<div>child component</div>

</script>

firebase_store.ts

import { writable } from "svelte/store";

export const firebaseStore = writable(null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment