Until recently, it really sucked trying to get select state in a form-independent way.
I rectified this situation by PRing a <FormName>
component that allows you to get the name of the enclosing form element, and created a library redux-form-reselect
for adapting the redux-form selectors. For example:
// @flow
import * as React from 'react'
import {connect} from 'react-redux'
import {
isSubmitting,
hasSubmitSucceeded,
hasSubmitFailed,
getFormError,
FormName,
} from 'redux-form'
import {createStructuredFormSelector} from 'redux-form-reselect'
import SubmitStatus from './SubmitStatus'
type Props = {
submitting: boolean,
submitSucceeded: boolean,
submitFailed: boolean,
error: ?Error,
}
export default class SubmitStatusContainer extends React.Component<Props> {
ConnectedSubmitStatus = connect(createStructuredFormSelector({
// createStructuredFormSelector converts all of these selectors
// to use the form name passed as the `form` prop to
// ConnectedSubmitStatus.
submitting: isSubmitting,
submitSucceeded: hasSubmitSucceeded,
submitFailed: hasSubmitFailed,
error: getFormError,
}))(SubmitStatus)
render(): ?React.Node {
const {ConnectedSubmitStatus} = this
return (
<FormName>
{({form}) => <ConnectedSubmitStatus {...this.props} form={form} />}
</FormName>
)
}
}