prescottprue / react-redux-firebase

Redux bindings for Firebase. Includes React Hooks and Higher Order Components.
https://react-redux-firebase.com
MIT License
2.55k stars 559 forks source link

FirebaseError: Function CollectionReference.add() requires its first argument to be of type object, but it was: a function #1005

Closed IkennaU closed 3 years ago

IkennaU commented 3 years ago

Pls Help, each time i try to submit, it gives the error... FirebaseError: Function CollectionReference.add() requires its first argument to be of type object, but it was: a function

pls help me out

import React, { useState } from "react"; import { Link } from "react-router-dom"; import { useFirestore } from "react-redux-firebase"; import { useFirestoreConnect } from "react-redux-firebase"; import PropTypes from "prop-types";

function AddClient(props) { const firestore = useFirestore();

let initialState = { firstName: "", lastName: "", email: "", phone: "", balance: "", }; const [clients, setClients] = useState(initialState); const { firstName, lastName, email, phone, balance } = clients;

useFirestoreConnect([{ collection: "client" }]);

const onChange = (e) => setClients({ ...clients, [e.target.name]: e.target.value });

const onSubmit = (e) => { e.preventDefault(); const newClient = setClients;

return firestore
  .add({ collection: "client" }, newClient);

};

return (

Back To Dasboard
Add Client

); }

AddClient.propTypes = {};

export default AddClient;

prescottprue commented 3 years ago

As the error message indicates, a function is being passed instead of an object value.

newClient will be a function because of the line:

const newClient = setClients;

setClients is a function because of this line here:

const [clients, setClients] = useState(initialState);

Since this is an implementation question you usually get a faster and more complete response if you reach out over Gitter

IkennaU commented 3 years ago

Thanks