Skip to content

Commit

Permalink
Added SingletonContextProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
H authored and H committed Jul 19, 2023
1 parent 2a7012f commit 47b6da1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/components/Hero.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import logoTransistor from "@/images/logos/transistor.svg";
import logoTuple from "@/images/logos/tuple.svg";
import clsx from "clsx";

import { useSingletonContext } from '@/pages/SingletonContextProvider';

export const FancyUnderline = ({ className, children, ...props }) => {

return (
<span className={clsx("relative whitespace-nowrap", className)}>
<svg
Expand All @@ -30,6 +33,9 @@ export const FancyUnderline = ({ className, children, ...props }) => {
};

export function Hero() {

// const { state, setState } = useSingletonContext();

return (
<Container className="pb-16 pt-20 text-center lg:pt-32">
<h1 className="mx-auto max-w-4xl font-display text-5xl font-medium tracking-tight text-slate-900 sm:text-7xl">
Expand Down
26 changes: 26 additions & 0 deletions src/pages/SingletonContextProvider.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { createContext, useState, useContext } from 'react';

// Create a context
const SingletonContext = createContext();

// Create a provider
export function SingletonContextProvider({ children }) {
const [state, setState] = useState('singleton');

// make sure state is only created once
let contextValue = useContext(SingletonContext);
if (!contextValue) {
contextValue = { state, setState };
}

return (
<SingletonContext.Provider value={contextValue}>
{children}
</SingletonContext.Provider>
);
}

// Create a hook to use the SingletonContext, this is just to simplify using the context.
export function useSingletonContext() {
return useContext(SingletonContext);
}
17 changes: 10 additions & 7 deletions src/pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Testimonials } from "@/components/Testimonials";
import { siteMeta } from "@/lib/siteMeta";

import { ChakraProvider } from '@chakra-ui/react'
import { SingletonContextProvider } from './SingletonContextProvider'

import { Text } from '@chakra-ui/react'

Expand Down Expand Up @@ -55,13 +56,15 @@ export default function Home() {
<Header />
<main>
<ChakraProvider>
<Hero />
<PrimaryFeatures />
<BlogArea />
<CallToAction />
{/* <Testimonials /> */}
<Pricing />
{/* <Faqs /> */}
<SingletonContextProvider>
<Hero />
<PrimaryFeatures />
<BlogArea />
<CallToAction />
{/* <Testimonials /> */}
<Pricing />
{/* <Faqs /> */}
</SingletonContextProvider>
</ChakraProvider>
</main>
<Footer />
Expand Down

0 comments on commit 47b6da1

Please sign in to comment.