Skip to content

Latest commit

 

History

History
59 lines (46 loc) · 1.11 KB

Value.md

File metadata and controls

59 lines (46 loc) · 1.11 KB

Value

The Value component is a generic component to store a some raw string/number value.

import { Value } from 'react-powerplug'
<Value initial="React">
  {({ value, setValue }) => (
    <Select
      label="Choose one"
      options={['React', 'Preact', 'Vue']}
      value={value}
      onChange={setValue}
    />
  )}
</Value>
<Value initial="first">
  {({ value, setValue }) => {
    const bindRadio = radioValue => ({
      selected: value === radioValue,
      onClick: () => setValue(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 = '' (optional)
Specifies the initial value state, must be an string or number.
By default, the initial value state is an empty string.

Value Children Props

TL;DR: { value, setValue }

value
number
Your value state

setValue
(value: string | number) => void
Set the value state