Javascript 反应状态挂钩-Can';无法清除表单数据上的状态

Javascript 反应状态挂钩-Can';无法清除表单数据上的状态,javascript,reactjs,Javascript,Reactjs,这里有点新手。正在尝试提交一个博客帖子表单,包括标题、作者和URL。我可以正确提交表单,并且值保存在数据库中,但我无法从表单中清除数据 我保持着这样的状态 const [newBlog, setNewBlog] = useState({ url: "", author: "", title: "" }); 以及处理表单更改以更新状态,如下所示: const handleBlogChange = e => { const { name, value } = e.target

这里有点新手。正在尝试提交一个博客帖子表单,包括标题、作者和URL。我可以正确提交表单,并且值保存在数据库中,但我无法从表单中清除数据

我保持着这样的状态

  const [newBlog, setNewBlog] = useState({ url: "", author: "", title: "" });
以及处理表单更改以更新状态,如下所示:

  const handleBlogChange = e => {
    const { name, value } = e.target;
    setNewBlog({ ...newBlog, [name]: value });
  };
一个my输入字段的设置示例(所有三个字段都相同)

我还尝试了不同的变体,将数据保留在表单中,没有错误,但没有清除表单。这方面的例子包括

setNewBlog(''), setNewBlog([]) and 
setNewBlog(newBlog.title='')

什么都没用

为什么你试图将新的博客状态设置为与开始时不同的状态?为什么不
setNewBlog({url:,作者:,标题:})
?这样使用会更好。setBlogs((prevBlogsState)=>{…prevBlogsState,data});如果你想保留上一个新的博客url,你可以这样做;setNewBlog((prevNewBlogState)=>{…prevNewBlogState,标题:,作者:});谢谢伙计们,@azium工作得很好,我想我已经盯着这个太久了。
const addBlog = event => {
    event.preventDefault();

    const { url, title, author } = newBlog;

    const blogObject = {
      url,
      title,
      author
    };

    blogService
      .create(blogObject)
      .then(data => {
        setBlogs(blogs.concat(data));
        showMessage(`Success! ${newBlog.title} by ${newBlog.author} was added`);
        // setNewBlog([...newBlog, { url: "", title: "", author: "" }]);
      })
      .catch(error => {
        showMessage(
          `Sorry can't add blog. Here's why: ${error.response.data.error}`,
          false
        );
      });
  };
setNewBlog(''), setNewBlog([]) and 
setNewBlog(newBlog.title='')