Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

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';constApp=()=>(<SessionProvider>
// nested code
</SessionProvider>);
classHeaderextendsReact.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,// withSessionupdateSession: PropTypes.func.isRequired,// withSession};exportdefaultwithSession(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';constApp=()=>(<SessionProviderdefaults={{data: null}}>
// nested code
</SessionProvider>);

license

MIT | @davalapar

About

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

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages