Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
/ session-context Public archive

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

License

Notifications You must be signed in to change notification settings

davalapar/session-context

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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