By default, the export package name for all APIs in this section is: @modern-js/runtime/model
.
If Reduck is integrated separately from Modern.js, the export package name is: @modern-js-reduck/react
.
The original type of Reduck is complex. The following type definition shows the simplified type information. For the original type, see connect.
Connect
is the same as useModel
and is the corresponding HOC-style API. It is recommended to use the Hook-style useModel
first.
models
: passed one or more Models. When models
is an array type parameter, the last two params can be a function for filtering State (SelectStateToProps
type) and a function for filtering Actions (SelectActionsToProps
type).
SelectStateToProps
: modelStates
is an array of the State of the passed Model object, ownProps
is the props received by current component. The data returned by SelectStateToProps
is passed to the props of the component. When the SelectStateToProps
parameter is not passed in models
, the States of all Models are merged and passed to the props of the component.
SelectActionsToProps
: modelActions
is an array of the Action of the passed Model object, ownProps
is the props received by current component. returned by SelectActionsToProps
is passed to the props of the component. When the SelectActionsToProps
parameter is not passed in models
, the Action of all Models are merged and passed to the props of the component.
options
: Optional parameter for auxiliary configuration. Currently supports setting forwardRef
, which is used to control whether to forward the ref
of the component. The default value is false
, which means that the ref
is not forwarded. Set to { forwardRef: true }
, which means to forward ref
.
Returns a HOC: receives an component, returns a component with extra State and Actions injected on props
.