The Wayback Machine - https://web.archive.org/web/20230221163434/https://github.com/davalapar/session-context
Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

davalapar/session-context

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

session-context

Session state using React.Context.

basics

import { SessionProvider } from 'session-context';

const App = () => (
  <SessionProvider>
    // nested code
  </SessionProvider>
);
class Header extends React.Component {
  componentDidMount() {
    const { updateSession } = this.props;
    fetchExternalCode()
      .then((data) => {
        updateSession({ data });
      });
  }
  render() {
    const { session } = this.props;
    return (
      <div>
        { session.data }
      </div>
    );
  }
}

Header.propTypes = {
  session: PropTypes.object.isRequired, // withSession
  updateSession: PropTypes.func.isRequired, // withSession
};

export default withSession(Header);

using defaults props for session

  • useful when you're loading a session state from window.__STATE__ and the like
import { SessionProvider } from 'session-context';

const App = () => (
  <SessionProvider defaults={{ data: null }}>
    // nested code
  </SessionProvider>
);

license

MIT | @davalapar

About

Session state using React.Context. (not yet npm published, too busy)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published