Skip to content

Latest commit

 

History

History
80 lines (68 loc) · 1.68 KB

Value.mdx

File metadata and controls

80 lines (68 loc) · 1.68 KB
name menu
Value
1. State Containers

import { Props, Prop, ChildrenProps, ChildrenProp } from '../_ui/PropsTable' import { Value } from '../../dist/react-powerplug.esm'

Value

A generic component for storing raw data values.

Usage

import { Value } from 'react-powerplug'
<Value initial="React">
  {({ value, set, reset }) => (
    <>
      <Select
        label="Choose one"
        options={['React', 'Preact', 'Vue']}
        value={value}
        onChange={set}
      />
      <Button onClick={reset}>Reset to initial</Button>
    </>
  )}
</Value>
<Value initial="first">
  {({ value, set }) => {
    const bindRadio = radioValue => ({
      selected: value === radioValue,
      onClick: () => set(radioValue),
    })

    return (
      <form>
        <RadioCheck {...bindRadio('first')}>First radio</RadioCheck>
        <RadioCheck {...bindRadio('second')}>Second radio</RadioCheck>
        <div>Selected value: {value}</div>
      </form>
    )
  }}
</Value>

Props

Specifies the initial `value` state. The onChange event of the Value is called whenever the on state changes. Receive state as function. It can also be `render` prop.

Children Props

Your `value` state value Arbitrary set a value to `value` state Reset `value` to initial state