亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

React - HTML 元素內部到字符串

React - HTML 元素內部到字符串

慕森王 2023-09-28 16:19:27
快速查看我正在嘗試做的事情: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在反應文檔中,它說這會導致問題,因為它正在調用具有依賴性的東西,但我不知道它們在哪里?
查看完整描述

2 回答

?
ibeautiful

TA貢獻1993條經驗 獲得超6個贊

我不確定如何標記為重復,

基本上你想將字符串呈現為 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>


查看完整回答
反對 回復 2023-09-28
?
犯罪嫌疑人X

TA貢獻2080條經驗 獲得超4個贊

JavaScript_Lessons_Objects.js


{

    titleName: "Indorction",

    heading: 'Welcome to JavaScript',

    iconName: faDotCircle,

    description: [

      `

       Do we even need to introduce <b class="hal">JavaScript</b>? It’s one of the most 

       popular programming languages on the planet!.

      `

   ],

},

課程.jsx


{ReactHtmlParser(this.props.lesson[this.state.indexDescription]["description"])}


查看完整回答
反對 回復 2023-09-28
  • 2 回答
  • 0 關注
  • 133 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號