title: What is wrong with my React.js code for blog comment feature
body: <p>I created a comment feature in my node.js blog application. I am using Mongodb data base. Everything works fine in postman. I can create new comments. However, I am trying to replicate the same in my client side via React.js. I think I have exhausted all my ideas. Here is the error message I keep getting each time I try to create a new comment from client side: This error is console.log from the catch(err) in backend.</p>
  <pre><code>undefined
  CastError: Cast to ObjectId failed for value &quot;:id&quot; (type string) at path &quot;_id&quot; for model &quot;Post&quot;
  </code></pre>
  <p><strong>Post Model</strong></p>
  <pre><code>//creating the user models for the database
  
  const mongoose = require(&quot;mongoose&quot;); //import mongoose
  const Schema = mongoose.Schema;
  
  const PostSchema = new mongoose.Schema(
   {
     
      title:{
          type: String,
          required: true,
          unique: true,
         
      },
      description:{
          type: String,
          required: true, 
      },
      postPhoto:{
          type: String,
          required:false,
      },
     username:{
          type: Schema.Types.ObjectId, 
          ref: 'User'
      },
      categories:{
         type: Array,
      },
     comments: [{
           type: mongoose.Schema.Types.ObjectId,
           ref: 'Comment',
           unique: true,
         }]
     
     }, {timestamps: true},
  
    );
   //exporting this schema
   module.exports = mongoose.model(&quot;Post&quot;, PostSchema); //the module name is &quot;Post&quot;
  </code></pre>
  <p><strong>Comment Model</strong></p>
  <pre><code>const mongoose = require(&quot;mongoose&quot;); //import mongoose to be used
  const Schema = mongoose.Schema;
  
  const CommentSchema = new mongoose.Schema(
   {
      commentdescription:{
          type: String,
          required: true, 
      },
     author:{
          type: Schema.Types.ObjectId, 
          ref: 'User',
          
      },
     
   
   }, {timestamps: true}
  );
  //exporting this schema
  module.exports = mongoose.model(&quot;Comment&quot;, CommentSchema); //the module name is &quot;Post&quot;
  </code></pre>
  <p><strong>create new comment and push to post codes</strong></p>
  <pre><code>//creating catergory logic
  
   router.post(&quot;/posts/:id/comment&quot;, async (req, res) =&gt;{
   const newComment = new Comment(req.body);//we create a new comment for the database
      
   try{
      //we need to try and catch the new comment and save it
  
      const currentPost = await Post.findByIdAndUpdate(req.params.id)//we need to find the post  that has the comment via the id
          currentPost.comments.push(newComment)//we need to push the comment into the post
  
          await newComment.save();
          await currentPost.save()//we saved the new post with the comment
      res.status(200).json(currentPost)
     }catch(err){
      console.log(err)
      res.status(500).json(err)
    }
   })
  </code></pre>
  <p><strong>What I have written in React</strong></p>
  <pre><code>const [commentdescription, setCommentDescription] = useState('')
  const [postId, setPostId] = useState()
   
    //function to create comment
   const handleComment = async ()=&gt;{
   const newComment = {
      _id: postId,
      author: user._id,
      commentdescription,
  };
  
  try{
      await axios.post(&quot;/posts/:id/comment&quot;, newComment);
       
  }catch(err){
      console.log(err)
  }
   }
  </code></pre>
  <p>Everything works fine in postman. I know I am missing something in react.</p>