New:Microsoft Teams Notifications Are Now Available in Socket.Learn more →
Get Started

@stardust-ui/react-bindings

Package Overview
Dependencies
Maintainers
6
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stardust-ui/react-bindings

A set of components and hooks to build components libraries and UI kits.

Source
npmnpm
Version
0.39.0-0
Version published
Weekly downloads
4
-87.1%
Maintainers
6
Weekly downloads
 
Created
Source

@stardust-ui/react-bindings

A set of reusable components and hooks to build component libraries and UI kits.

  • Installation
  • Hooks

Installation

NPM

npm install --save @stardust-ui/react-bindings

Yarn

yarn add @stardust-ui/react-bindings

Hooks

useStateManager()

A React hook that provides bindings for state managers.

Usage

The examples below assume a component called <Counter> will be used this way:

import { useStateManager } from "@stardust-ui/react-bindings";
import { createManager, ManagerFactory } from "@stardust-ui/state";

type InputProps = {
  value?: string;
  defaultValue?: string;
  onChange: (value: string) => void;
};
type InputState = { value: string };
type InputActions = { change: (value: string) => void };

const createInputManager: ManagerFactory<InputState, InputActions> = config =>
  createManager<InputState, InputActions>({
    ...config,
    actions: {
      change: (value: string) => () => ({ value })
    },
    state: { value: "", ...config.state }
  });

const Input: React.FC<InputProps> = () => {
  const [state, actions] = useStateManager(createToggleManager, props, {
    autoControlledProps: ["value"]
  });

  return (
    <input
      onChange={e => {
        actions.change(e.target.value);
        if (props.onChange) onChange(e.target.value);
      }}
      value={state.value}
    />
  );
};

Reference

const [state, actions] = useStateManager(createToggleManager, props, {
  autoControlledProps: ['value']
})
const [state, actions] = useStateManager(
  managerFactory: ManagerFactory<State, Actions>, 
  props: Props,
  options: UseStateManagerOptions<Props>,
)
  • managerFactory - a factory that implements state manager API
  • props - all component props
  • options.autoControlledProps - optional and is required only if your component implements controlled mode.

FAQs

Package last updated on 23 Sep 2019

Related posts