Open
Description
Feature request: Easier access to errors from firestoreConnect (reading data) in components.
What is the current behavior?
When a error arises when requesting data the error information is stored in the Redux state at firestore.errors.byQuery.[query id]
. A query id could simply be the name of a collection like todos
, but when specifying a limit
it becomes todos?limit=6
making it hard to read out and forward to a component.
What is the expected behavior?
I'd love an easier way to pass that those errors as a prop to a component.
I figured out a work around using storeAs
:
import React from 'react';
import { connect } from 'react-redux';
import { firestoreConnect, isLoaded, isEmpty } from 'react-redux-firebase';
import { compose } from 'redux';
function List({ todos, error }) {
if (!isLoaded(data)) return 'Loading...';
if (isEmpty(data)) return null;
if (error) return error.message;
return (
<ul>
{todos.map(todo => (
<li key={todo.id}>{todo.name}</li>
))}
</ul>
);
}
const QUERY_ID = 'todos';
export default compose(
firestoreConnect([
{
collection: 'todos',
storeAs: QUERY_ID,
},
]),
connect(state => ({
[QUERY_ID]: state.firestore.ordered[QUERY_ID],
error: state.firestore.errors.byQuery[QUERY_ID],
}))
)(List);
I'm using:
- firebase:
5.7.0
- react-redux-firebase:
2.2.6
- redux-firestore:
0.8.0