Nothing Pleases Me

    quickcontext
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.0 • Public • Published

    QuickContext

    ContextAPI state management made easy

    NPM JavaScript Style Guide

    Install

    npm install --save quickcontext

    Usage

    Changing values in a context as simple as:

    this.context.store.value = newValue;

    Your context module:

    import {createContext} from 'quickcontext';
     
    const eContext = createContext({
      clicks: 0,
    });
     
    export const Context = eContext.Context;
    export const Consumer = eContext.Consumer;
    export const Provider = eContext.Provider;

    Your app:

    import {Provider} from './Context';
    import {Component} from './Component';
     
    export const App = () =>
      <Provider>
        <Component/>
      </Provider>

    Your component:

    import React from 'react';
    import {Context} from './Context';
     
    export class Component extends React.Component {
      click = () => this.context.store.clicks = Math.random()
     
      render() {
        return <React.Fragment>
          <button onClick={this.click}/>
          Clicked: {this.context.store.clicks}<br/>
        </React.Fragment>
      }
    }
     
    Component.contextType = Context;

    For more information have a look at example.

    License

    MIT © PixelsCommander

    Keywords

    none

    Install

    npm i quickcontext

    DownloadsWeekly Downloads

    0

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    37.6 kB

    Total Files

    8

    Last publish

    Collaborators

    • pixelscommander