New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-preset

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-preset

Smash your props into single preset prop

  • 0.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
36
increased by33.33%
Maintainers
1
Weekly downloads
 
Created
Source

React Preset

npm npm bundle size CI Gitter

Smash your props into single `preset` prop.

Edit react-preset

Quick start

npm install react-preset
  1. Create preset object and extend TypeScript definitions:
// preset.tsx
const preset = {
  // Preset group name
  button: {
    // Single preset
    save: {
      // These props should be handled by component
      children: 'Save',
      appearance: 'primary'
    },
    cancel: {
      children: 'Cancel',
      appearance: 'minimal'
    }
  }
}

declare module 'react-preset' {
  export interface DefaultPreset extends Required<typeof preset> {}
}

export default preset
  1. Wrap your App component with preset provider
// App.tsx
import {PresetContext} from 'react-preset'
import Button from './Button'
import preset from './preset'

const App = () => (
  <PresetContext.Provider value={preset}>
    <Button preset="cancel" />
    <Button preset="save" />
  </PresetContext.Provider>
);
  1. Wrap your component with withPreset
// Button.tsx
import * as React from 'react'
import {withPreset} from 'react-preset'

type Props = {
  appearance: 'minimal' | 'primary'
}

const Button: React.FC<Props> = (props) => <button {...props}/>

export default withPreset('button')(Button)

Check example directory to learn more.

API

PresetContext

Used to provide presets to components.

<PresetContext.Provider value={preset}>
  <Page />
</PresetContext.Provider>

usePreset

Hook used to get access to all presets inside component.

const MyComponent = () => {
  const presets = usePreset()
  // presets.button.save
}

withPreset(groupName)(component)

Apply preset to component.

const Card = () => <div {...props} />

export default withPreset('card')(Card)

Keywords

FAQs

Package last updated on 10 May 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