import React from 'react' import { FormState, FieldState, bindInput } from 'formstate-x' import { observer } from 'mobx-react' import { Form, FormItem, useFormstateX, InputGroup, InputGroupItem, useStateInFormItem } from 'react-icecream/form-x' import { AddThinIcon, RemoveThinIcon } from 'react-icecream/icons' interface CounterProps { state: FieldState } const Counter = observer(function _Counter({ state }: CounterProps) { // `useStateInFormItem` registers Counter's state to FormItem useStateInFormItem(state) const { value, onChange } = bindInput(state) return ( onChange(value + 1)} /> {value} onChange(value - 1)} /> ) }) export default observer(() => { const state = useFormstateX(() => new FormState({ count: new FieldState(0).validators(v => v <= 0 && 'Positive required.') }), []) return (
alert(v.count)}> {/* So we don't need to pass `state.$.count` to `FormItem` here */}
) })