import { unstable_useDispatchEffect, useStateManager } from '@fluentui/react-bindings'; import { createManager, ManagerFactory } from '@fluentui/state'; import { shallow } from 'enzyme'; import * as React from 'react'; import * as ReactTestUtils from 'react-dom/test-utils'; type TestState = { value: string }; type TestActions = { change: (value: string) => void; clear: () => void }; const createTestManager: ManagerFactory = config => createManager({ ...config, actions: { change: (value: string) => () => ({ value }), clear: () => () => ({ value: '' }), }, state: { value: '', ...config.state, }, }); type TestComponentProps = Partial & { onChange: (e: React.ChangeEvent | React.MouseEvent, value: TestComponentProps) => void; defaultValue?: string; value?: string; }; const TestComponent: React.FunctionComponent = props => { const [dispatch, dispatchEffect] = unstable_useDispatchEffect((e, prevState, nextState) => { if (prevState.value !== nextState.value) { props.onChange(e as React.ChangeEvent | React.MouseEvent, { ...props, value: nextState.value, }); } }); const { state, actions } = useStateManager(createTestManager, { mapPropsToInitialState: () => ({ value: props.defaultValue }), mapPropsToState: () => ({ value: props.value }), sideEffects: [dispatchEffect], }); return ( <> dispatch(e, actions.change, e.target.value)} value={state.value} />