Skip to content

Latest commit

 

History

History
63 lines (50 loc) · 1.14 KB

File metadata and controls

63 lines (50 loc) · 1.14 KB

Value

The Value component is a generic component to store a some raw data value.

import { Value } from 'react-powerplug'
<Value initial="React">
  {({ value, set }) => (
    <Select
      label="Choose one"
      options={['React', 'Preact', 'Vue']}
      value={value}
      onChange={set}
    />
  )}
</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>

Value Props

initial (required)
Specifies the initial value state.

onChange (optional)
The onChange event of the Value is called whenever the value state changes.

Value Children Props

TL;DR: { value, set }

value
T
Your value state

set
(value: T | (value: T) => T) => void
Set or over the value state

reset
() => void
Reset value to initial