0

I have a mongoose schema that looks like this:

const productSchema = mongoose.Schema({
  title: String,
  type: String,
  allStock: Number,
  inStock: Number,
  img: String,
  desc: String,
  child: [{
    uid: Number,
    rented: {
      type: Boolean,
      default: false,
    },
    rentedData: {
      type: Date,
      default: new Date(),
    },
  }],
})

In my form I store the values in the state:

const [productData, setProductData] = useState({title:'',type:'',allStock:'',inStock:'',img:'',desc:''});

and then within a form set the state like so:

<input type="text" value={productData.title} onChange={(e)=> setProductData({...productData, title: e.target.value})}/>

the form has an onSubmit which then dispatches the data, I am wondering how I would create an entry for a child value would it be something like:

<input type="text" value={productData.child[{rented}]} onChange={(e)=> setProductData({...productData, child: [rented: e.target.value]})}/>

New to working with backend with react, all help welcome!

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
Destinneh
  • 33
  • 5
  • 1
    Avoid adding images or screenshots of code. Paste it directly into the question next time. – Mr. Polywhirl Apr 16 '21 at 15:52
  • Does this answer your question? [Whats the best way to update an object in an array in ReactJS?](https://stackoverflow.com/questions/28121272/whats-the-best-way-to-update-an-object-in-an-array-in-reactjs) – Emile Bergeron Apr 16 '21 at 17:04

0 Answers0