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

react-logic-hoc

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-logic-hoc

HOC for provide logic deep into component tree

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

React Logic HOC

NPM version NPM license NPM total downloads NPM monthly downloads

Idea

  1. Write dumb components based on props only
  2. Consume hook from context
  3. Get new props with some logic from hook
  4. Now dumb components is smart components

Getting Started

Create component

// create context
import React from 'react';
import withLogic from 'react-logic-hoc';

export const ComponentContext = React.createContext();

// create component
export const Component = (props) => {
    /* Component */
};

// wrap component
const WithLogicComponent = withLogic(ComponentContext)(Component);

export default WithLogicComponent;

Provide logic

// create logic hook
const useComponentLogic = (props) => {
    /* Logic */

    return propsWithLogic;
};

// provide logic
<ComponentContext.Provider value={useComponentLogic}>
    <WithLogicComponent />
</ComponentContext.Provider>

Advanced

Use composeProviders for reduce complexity

import React from 'react';
import { composeProviders } from 'react-logic-hoc';

// full page logic
const LogicProvider = composeProviders(
    [HeaderContext, useHeaderLogic],
    [SidebarContext, useSidebarLogic],
    [ContentContext, useContentLogic]
);

const Page = () => (
    <LogicProvider>
        <Main />
    </LogicProvider>
);

API

withLogic

takes one argument Context and return HOC

composeProviders

takes arguments [Context, value] and return component that render children

Keywords

FAQs

Package last updated on 12 Feb 2020

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