Skip to content

Commit

Permalink
fix: typo in context code block (#989)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
tomheaton and kodiakhq[bot] authored Dec 30, 2024
1 parent 9c8959f commit 828abd7
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/routes/reference/component-apis/create-context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,36 @@ For example:
```ts title="/context/counter.ts"
import { createContext } from "solid-js";

export const DEFAULT_COUNT = 0
const INTIAL_STORE_SETTER = {
increment: () => void,
decrement: () => void
export const INITIAL_COUNT = 0;

const INITIAL_STORE_SETTER = {
increment: () => {},
decrement: () => {}
};

export const CounterContext = createContext([
{ count: INITIAL_COUNT },
INTIAL_STORE_SETTER
INITIAL_STORE_SETTER
]);
```

With the context created in its own module, you can use to instantiate the context provider.

```ts title="/context/counter-component.tsx"
import { createStore } from 'solid-js/store';
import { CounterContext, DEFAULT_COUNT } from "./counter.ts";
import { CounterContext, INITIAL_COUNT } from "./counter.ts";

export function CounterProvider(props) {
const [value, setValue] = createStore({ count: props.initialCount || DEFAULT_COUNT })
const [value, setValue] = createStore({ count: props.initialCount || INITIAL_COUNT })

const counter = [
const counter = [
value,
{
increment() {
setValue("count", currentCount => currentCount + 1)
},
decrement() {
setValue("count", currentcount => currentCount - 1)
setValue("count", currentCount => currentCount - 1)
},
},
]
Expand Down Expand Up @@ -98,4 +99,4 @@ interface Context<T> {
}

function createContext<T>(defaultValue?: T): Context<T | undefined>
```
```

0 comments on commit 828abd7

Please sign in to comment.