Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-client-session

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-client-session

A simple object to manage a client session in a React app

  • 0.0.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
643
decreased by-11.68%
Maintainers
1
Weekly downloads
 
Created
Source

react-session

npm version

A simple object to manage client session data in a React app. This is not synchronized with server side sessions.

Installation

npm install react-client-session --save

Usage

A simple example. Download and run the demo for more examples, or browse the examples here.

  1. Optionally set the storage type in the base App, and create a key value pair ... for example, username.

Supported storage types are memory(default), cookie, localStorage and sessionStorage.

NOTE: When using cookie store type, all key value pairs that are set via ReactSession.set(key, value); are serialized as JSON in to one single cookie called __react_session_<DOMAIN>

import React from 'react';
import { Switch, Route } from 'react-router-dom';
import { ReactSession } from 'react-client-session';

function App() {
  ReactSession.setStoreType("localStorage");
  ReactSession.set("username", "Bob");

  return (
    <div>
      <Switch>
        // Routes 
      </Switch>
    </div>
  );
}

export default App;
  1. Display the username from somewhere else in your App.
import React from 'react';
import { ReactSession } from 'react-client-session';

function MyComponent() {
  const username = ReactSession.get("username");

  return (
    <p>User Name is: {username}</p>
  )
}

export default Simple;

Download Examples

git clone https://github.com/grizzthedj/react-session.git
cd react-session
npm install
gulp demo
Browse http://localhost:8080

Keywords

FAQs

Package last updated on 12 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc