API Quick Start
Load data
Construct a Firestore query, attach listeners for updates and get the data from the selector.
const MyController = () => {
// 1. construct query
const taskQuery = {
collection: `workspace/MySpace/tasks`,
where:[
['status', '<', 1],
['deleted', '==', false]
],
orderBy: ['createdAt', 'desc'],
storeAs: 'tasksStarted',
}
// 2. load & attached listeners for document changes
useFirestoreConnect([taskQuery]);
// 3. Get results
const tasks = useSelector(state =>
state.firestore.cache['tasksStarted'].docs
);
// 4. Display when the data returns
return (<ol>
{tasks && tasks.map(({id, title}) => (
<li key={id}>title</li>
))}
</ol>);
};
Saving Data
Use redux-firestore's mutate function to queue changes to Firestore
and see the optimitic results instantly in the UI.
const MyController = (task) => {
const changeTitle = useCallback(({id, path, title}) => {
dispatch(
createMutate({
doc: id,
collection: path,
title
}))
.catch((error) => { alert(error) });
})
return (<TaskView onSave={changeTitle} />);
};