New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

react-shared-state-hooks

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-shared-state-hooks

Shared state hooks for React

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

React Shared State Hook

A simple hook for sharing state efficiently between components in React.

This is not intended to replaced dedicated state management in complex or large application, but to provide a simpler way to share state betweek componnents that using the context API.

Example usage:

import React, { FC, Fragment } from 'react';
import { createSharedState } from 'react-shared-state-hook';

const initialValue = 0;
const useSharedState = createSharedState(initialValue);

const ChildComponent: FC = () => {
  const [state, setState] = useSharedState();

  return (
    <div
      style={{
        outline: '1px solid',
        padding: 10,
        margin: 10,
        display: 'inline-flex',
        columnGap: 10,
        flexBasis: 20,
      }}
    >
      <span>{state}</span>
      <input type="button" onClick={() => setState(state + 1)} value="Up" />
       
      <input type="button" onClick={() => setState(state + 1)} value="Down" />
    </div>
  );
};

const Example: FC = () => {
  return (
    <Fragment>
      <ChildComponent />
      <ChildComponent />
      <ChildComponent />
    </Fragment>
  );
};

Keywords

react

FAQs

Package last updated on 15 Jan 2022

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