I am using firestoreConnect
however the data seems to be never written to the state.
const Shipping = ({adoptions,cart,addresses,totals}) => {
console.log("Shipping Addresses ",addresses)
return <ViewCheckout to="/" cta="Next: Proceed Pay" totals={totals} >
<AddressBook />
{/* Add address section */}
<AddressForm />
</ViewCheckout>
}
const mapPropsToState = state => {
console.log("state",state)
return{
cart: state.cart,
totals: totalsSelector(state),
firebase: state.firebase,
addresses: state.firestore.data.addresses
}
}
export default compose(
firestoreConnect(['addresses']),
connect(mapPropsToState,null))(Shipping)
I see in redux-logger
that the data has been loaded however if I read the state the data is never loaded.
I add the logs from the state:
- When I dispatch action:
"@@reduxFirestore/DOCUMENT_ADDED"
the state has the firebase data with the addresses. - However. When I dispatch action:
CREATE_ADDRESS_SUCCESS
. Firebase data is not loaded anymore, in the previous state.
I see that the firebase data is never present in my component, and also any of the next actions that I dispatch from my reducers.
I can see that logging the state from the addAddress
function is also showing no firebase data on the state.
export function addAddress(data){
return (dispatch,getState, {getFirebase,getFirestore}) => {
const firesotre = getFirestore()
console.log("Action state",getState())
return firesotre.add({collection:'addresses'},
{...data,
createdAt: new Date()
})
.then( ()=> dispatch(createAddressSuccess()) )
.catch( ()=> dispatch(addressError()) )
}
}
Log data:
Redux Inspector shows two instances.
- One instance state captures all the actions that I created in the project. Does not updates with firebase.
- On the other the state behaves the opposite, only keep track of the state regarding the firebase. It does not listen to the application actions.
Any tips around?
I solved myself!
I forgot that I had used a gatsby plugin to create the store.
Rember when using Gatsby Check what you have in your config file!!! Otherwise, it seems that the code has taken his own life!