{{#template name="apiSession"}}

Session

`Session` provides a global object on the client that you can use to store an arbitrary set of key-value pairs. Use it to store things like the currently selected item in a list. What's special about `Session` is that it's reactive. If you call [`Session.get`](#session_get)`("currentList")` from inside a template, the template will automatically be rerendered whenever [`Session.set`](#session_set)`("currentList", x)` is called. {{> autoApiBox "Session.set"}} Example: ```js Tracker.autorun(function () { Meteor.subscribe("chat-history", {room: Session.get("currentRoomId")}); }); // Causes the function passed to Tracker.autorun to be re-run, so // that the chat-history subscription is moved to the room "home". Session.set("currentRoomId", "home"); ``` `Session.set` can also be called with an object of keys and values, which is equivalent to calling `Session.set` individually on each key/value pair. ```js Session.set({ a: "foo", b: "bar" }); ``` {{> autoApiBox "Session.setDefault"}} This is useful in initialization code, to avoid re-initializing a session variable every time a new version of your app is loaded. {{> autoApiBox "Session.get"}} Example: ```html