React - HTML 元素内部到字符串

快速查看我正在尝试做的事情:


import React, { useState, useEffect } from 'react';


const MainComponent = () => {

  const [element, setElement] = useState([]);

  const [setThings] = useSomething();

  useEffect(() => {

    setThings(element);

  }, [element]);

};


const useSomething = () => {

  const [things, setThings] = useState([]);

  // do stuff now that you've received things

  return [setThings];

};

以及另一个文件中的另一个钩子。这工作得很好,并且是在 ReactJS 中使用画布的绝佳解决方案。我有一个警告被抛出,我似乎无法通过我的研究来解决它:


  Line 150:7:  React Hook useEffect has a missing dependency: 'setThings'. Either include it or remove the dependency array  react-hooks/exhaustive-deps

在反应文档中,它说这会导致问题,因为它正在调用具有依赖性的东西,但我不知道它们在哪里?


慕森王
浏览 68回答 2
2回答

ibeautiful

我不确定如何标记为重复,基本上你想将字符串呈现为 HTML,这是一种危险的做法,所以要小心。const x = {        titleName: "Indorction",        heading: 'Welcome to JavaScript',        iconName: faDotCircle,        description: [            `            Do we even need to introduce <p>HTML element</p>? It’s one of the most popular programming             languages on the planet!            Ever visited a website that made you think…"Hey, this website is really cool and            `        ],    },在你的渲染函数中:<div dangerouslySetInnerHTML={{ __html: x.description }}></div>

犯罪嫌疑人X

JavaScript_Lessons_Objects.js{&nbsp; &nbsp; titleName: "Indorction",&nbsp; &nbsp; heading: 'Welcome to JavaScript',&nbsp; &nbsp; iconName: faDotCircle,&nbsp; &nbsp; description: [&nbsp; &nbsp; &nbsp; `&nbsp; &nbsp; &nbsp; &nbsp;Do we even need to introduce <b class="hal">JavaScript</b>? It’s one of the most&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;popular programming languages on the planet!.&nbsp; &nbsp; &nbsp; `&nbsp; &nbsp;],},课程.jsx{ReactHtmlParser(this.props.lesson[this.state.indexDescription]["description"])}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript