Skip to content

Latest commit

 

History

History
30 lines (25 loc) · 725 Bytes

State.md

File metadata and controls

30 lines (25 loc) · 725 Bytes

State

The State component uses the render prop pattern to expose React state to child elements. Use the State component to quickly test interactions in UI components.

Pass props to initialize state and use the update prop to update the state.

import React from 'react'
import { State } from '@compositor/kit'
import Counter from '../src/Counter'

const example = (
  <State
    count={0}
    render={({
      update,
      count
    }) => (
      <Counter
        value={count}
        onDecrement={e => update(state => ({ count: state.count - 1 }))}
        onIncrement={e => update(state => ({ count: state.count + 1 }))}
      />
    )}
  />
)