rpominov / react-demo

A React-component for creating demos of other components
MIT License
99 stars 9 forks source link

Demo.props.callback.withUpdate() #37

Open rpominov opened 8 years ago

rpominov commented 8 years ago

// before

<Demo
  props={{
    value: P.string(''),
    onChange: P.callback.log(),
  }}
>
  {
    (props, update) =>
      <Input
        {...props}
        onChange={value => { update({value}); props.onChange(value) }}
      />
  }
</Demo>

// after

<Demo target={Input} props={{
  value: P.string(''),
  onChange: P.callback.withUpdate((update, value) => {
    update({value});
    return value; // whatever returned will be logged
  }),
}} />