如何将输入的数据作为字符串获取并提交到我的React应用程序的`MDEditor`中?

huangapple go评论46阅读模式
英文:

How can i get the typed in data as string and submit in my `MDEditor` of react app

问题

以下是您要翻译的内容:

如何在我的React应用中提交`MDEditor`中的所有输入数据我已尝试以下方式提交但无法获得完整的数据作为字符串有人可以给我一些建议吗

import MDEditor from '@uiw/react-md-editor';

const [value, setValue] = React.useState("**创建新博客**");

const handleChange = (value) => {
  // 在这里更新状态...
  setValue(value);

  const fetchData = async (value) => {
    try {
      const res = await axios.post(`${appURL}/service/createBlog`, { value });

      if (res.data.success) {
        // 执行其他操作
      } else {
        // 处理失败情况
      }
    } catch (e) {
      console.log(e);
    }
  };
  fetchData();
};

<div className='container'>
  <MDEditor
    className='reactEditorArea'
    value={value}
    onChange={handleChange}
  />
</div>

请注意,我已经保留了代码的原样,只翻译了注释和文本部分。如果您有任何其他问题,请随时提问。

英文:

How can I submit all of the typed data in MDEditor in my react app ? I have tried the below way to submit, but i am not getting the whole types in data as string, could someone please advise me ?

import MDEditor from &#39;@uiw/react-md-editor&#39;;

const [value, setValue] = React.useState(&quot;**Create a new blog**&quot;);

const handleChange = (value) =&gt; {
  // Updating the state here... 
  setValue(value);
  
  const fetchData = async (value) =&gt; {
      try{
       
       const res = await axios.post(`${appURL}/service/createBlog`, {value });

        if (res.data.success) {
          // do rest of the 
        }
        else {
          
        }
       } catch (e){
            console.log(e);
           
        }
     }
     fetchData();
  
}

&lt;div className=&#39;container&#39;&gt;
    &lt;MDEditor
       className=&#39;reactEditorArea&#39;
       value={value}
       onChange={handleChange}
    /&gt;
&lt;/div&gt;

答案1

得分: 1

你的 fetchData 具有 value 属性,但你在调用它时没有使用 valuefetchData()

To-BE

const handleChange = (value) => {
  // ...
   fetchData(value);
}
英文:

Your fetchData has property value but you call it without value, fetchData().

To-BE

const handleChange = (value) =&gt; {
  // ...
   fetchData(value);
}

huangapple
  • 本文由 发表于 2023年2月14日 08:53:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75442534.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定