This module connect your component in the CMF environment.
- Source:
Example
import { cmfConnect } from '@talend/react-cmf';
function MyComponent(props) {
const onClick = (event) => {
props.dispatchActionCreator('myaction', event, { props: props });
};
return <button onClick={onClick}>Edit {props.foo.name}</button>;
}
function mapStateToProps(state) {
return {
foo: state.cmf.collection.get('foo', { name: 'world' }),
};
}
export default cmfConnect({
mapStateToProps,
});
(require("react-cmf/lib/cmfConnect"))(options) → {ReactComponent}
this function wrap your component to inject CMF props
Parameters:
Name | Type | Description |
---|---|---|
options |
object | Option objects to configure the redux connect |
- Source:
Returns:
- Type
- ReactComponent
Examples
The following props are injected:
- props.state
- props.setState
- props.initState (you should never have to call it your self)
- dispatch(action)
- dispatchActionCreator(id, event, data, [context])
support for the following props
- initialState (called by props.initState)
- didMountActionCreator (id or array of id)
- willUnMountActionCreator (id or array of id)
- componentId (or will use uuid)
- keepComponentState (boolean, overrides the keepComponentState defined in container)
- didMountActionCreator (string called as action creator in didMount)
- view (string to inject the settings as props with ref support)
- whateverExpression (will inject `whatever` props and will remove it)
options has the following shape:
{
componentId, // string or function(props) to compute the id in the store
defaultState, // the default state when the component is mount
keepComponent, // boolean, when the component is unmount, to keep it's state in redux store
mapStateToProps, // function(state, ownProps) that should return the props (same as redux)
mapDispatchToProps, // same as redux connect arg, you should use dispatchActionCreator instead
mergeProps, // same as redux connect
}
Methods
(static) getMergeProps(options)
Internal: you should not have to use this
return the merged props which cleanup expression props
call mergeProps if exists after the cleanup
Parameters:
Name | Type | Description |
---|---|---|
options |
object | { mergeProps, stateProps, dispatchProps, ownProps } |
- Source: