> For the complete documentation index, see [llms.txt](https://mile-hi-labs.gitbook.io/react-session/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mile-hi-labs.gitbook.io/react-session/api-documentation/session-context.md).

# Session Context

## Overview

This component uses the React Context API to make the `session` object available to all your components with minimal setup.

## SessionProvider

The `SessionProvider` Component adds the store to React's state hierarchy allowing you to pass it down to any component or add it to any component using the `withSession` function wrapper.

```javascript
import React from 'react';
import { SessionProvider, SessionContext } from '@mile-hi-labs/react-session';

const App = (store) => {

    return (
        <SessionProvider store={store} modelName='user' params={{include: 'settings' }}>
            <Router>
        </SessionProvider>
    )
}

export default App;
```

## SessionContext

The `SessionContext` is the actual context that will contain the store after the SessionProvider has been declared in your application. You should really only use the SessionContext if you need access to the \`session\` in the same component where you declare the StoreProvider.

```javascript
import React from 'react';
import { SessionProvider, SessionContext } from '@mile-hi-labs/react-session';

const App = (store) => {

    return (
        <SessionProvider store={store} modelName='user' params={{include: 'settings' }}>
            <SessionContext.Consumer>
                {context => (
                    <Router session={context} />
                )}
            </SessionContext.Consumer>
        </SessionProvider>
    )
}

export default App;
```

## withStore

The `withStore()` function is a wrapper for any component in your application  that will make the `store` object available to that component.

```javascript
import React from 'react';
import { withSession } from '@mile-hi-labs/react-session';

const Router = (props) => {
    return (
        <Switch>
            <Route exact path='/' render={routeProps => <IndexRoute {...passedProps} {...routeProps}/>} />
        </Switch>
    )
}

export default withSession(Router);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mile-hi-labs.gitbook.io/react-session/api-documentation/session-context.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
