Redux Resource Prop Types
A collection of prop-types objects.

Other Guides

Old Documentation
Migration Guides

Installation

Install redux-resource-prop-types with npm:
npm install redux-resource-prop-types --save
Then, import the prop types that you need:
1
import { resourcesPropType } from 'redux-resource-prop-types';
Copied!

Usage

If you're using React, refer to the Typechecking with PropTypes guide on how to use the exported prop types. If you're not using React, refer to the documentation of the prop-types library.
We recommend using the prop types in this library to build your own prop types, which you can reuse throughout your application.

idPropType

Validates a single resource ID.
Tip: This prop type requires that your IDs be either strings or numbers.
1
import PropTypes from 'prop-types';
2
import { idPropType } from 'redux-resource-prop-types';
3
4
MyComponent.propTypes = {
5
selectedBookIds: PropTypes.arrayOf(idPropType).isRequired
6
};
7
8
mapStateToProps(state) {
9
return {
10
selectedBookIds: state.books.selectedIds
11
};
12
}
Copied!

statusPropType

Validates the object returned by getStatus.
1
import { getStatus } from 'redux-resource';
2
import { statusPropType } from 'redux-resource-prop-types';
3
4
MyComponent.propTypes = {
5
booksReadStatus: statusPropType
6
};
7
8
mapStateToProps(state) {
9
return {
10
bookReadStatus: getStatus(state, 'books.meta[23].readStatus');
11
};
12
}
Copied!

requestStatusPropType

Validates that a value is one of the requestStatuses. Typically, you'll want to use statusPropType instead, but this can be useful when verifying the structure of your slice.
1
import { requestStatusPropType } from 'redux-resource-prop-types';
2
3
MyComponent.propTypes = {
4
bookRequestStatus: requestStatusPropType
5
};
6
7
mapStateToProps(state) {
8
return {
9
bookRequestStatus: state.books.meta[23].readStatus
10
};
11
}
Copied!

resourcePropType

Validates a resource. Similar to PropTypes.shape(), except that it enforces an ID.
1
import PropTypes from 'prop-types';
2
import { resourcePropType } from 'redux-resource-prop-types';
3
4
MyComponent.propTypes = {
5
book: resourcePropType({
6
name: PropTypes.string.isRequired,
7
releaseYear: PropTypes.number.isRequired
8
})
9
};
10
11
mapStateToProps(state) {
12
return {
13
book: state.books.resources[23]
14
};
15
}
Copied!

requestPropType

Validates a request object. Similar to PropTypes.shape(), except that it enforces ids, status, requestKey and resourceType. Typically, you won't need to use this, but it can be useful to verify the structure of your state.
1
import PropTypes from 'prop-types';
2
import { requestPropType } from 'redux-resource-prop-types';
3
4
MyComponent.propTypes = {
5
searchRequest: requestPropType({
6
statusCode: PropTypes.number.isRequired
7
})
8
};
9
10
mapStateToProps(state) {
11
return {
12
searchRequest: state.books.requests.search
13
};
14
}
Copied!