Skip to content

Update context.md #592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ interface ContextState {
// set the type of state you want to handle with context e.g.
name: string | null;
}
//set an empty object as default state
// set an empty object as default state
const Context = createContext({} as ContextState);
// set up context provider as you normally would in JavaScript [React Context API](https://reactjs.org/docs/context.html#api)
```
Expand Down Expand Up @@ -1586,14 +1586,14 @@ Notice the explicit type arguments which we need because we don't have a default

```ts
const currentUserContext = createContext<string | undefined>(undefined);
// ^^^^^^^^^^^^^^^^^^
// ^^^^^^^^^^^^^^^^^^^^^^^
```

along with the non-null assertion to tell TypeScript that `currentUser` is definitely going to be there:

```ts
return <div>HELLO {currentUser!.toUpperCase()}!</div>;
// ^
// ^
```

This is unfortunate because _we know_ that later in our app, a `Provider` is going to fill in the context.
Expand Down
6 changes: 3 additions & 3 deletions docs/basic/getting-started/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ interface ContextState {
// set the type of state you want to handle with context e.g.
name: string | null;
}
//set an empty object as default state
// set an empty object as default state
const Context = createContext({} as ContextState);
// set up context provider as you normally would in JavaScript [React Context API](https://reactjs.org/docs/context.html#api)
```
Expand Down Expand Up @@ -85,14 +85,14 @@ Notice the explicit type arguments which we need because we don't have a default

```ts
const currentUserContext = createContext<string | undefined>(undefined);
// ^^^^^^^^^^^^^^^^^^
// ^^^^^^^^^^^^^^^^^^^^^^^
```

along with the non-null assertion to tell TypeScript that `currentUser` is definitely going to be there:

```ts
return <div>HELLO {currentUser!.toUpperCase()}!</div>;
// ^
// ^
```

This is unfortunate because _we know_ that later in our app, a `Provider` is going to fill in the context.
Expand Down