如何将道具作为HTML标记传递给短划线中的元素

2024-09-29 21:37:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个短跑项目。我刚刚学习了dash中的Create your own components,我创建了一个简单的组件,即-文本区域。下面是组件的代码-

我的仪表盘组件/mydashcomponent.react.js在

import React, {Component} from 'react';
import PropTypes from 'prop-types';
export default class mydashcomponent extends Component {

render(){
    const {id,setProps,value} = this.props;
    return(
    <div id={id}>
       <textarea cols="150" rows="45" value={value} onChange={e => {
                     if (setProps) {
                         setProps({
                            value: e.target.value
                        });
                    } else {
                        this.setState({
                            value: e.target.value
                        })
                    }
                }} />
    </div>
    );
  }
}

mydashcomponent.defaultProps = {};

mydashcomponent.propTypes = {
   /**
   * The ID used to identify this component in Dash callbacks
   */
   id: PropTypes.string,

   /**
   * A label that will be printed when this component is rendered.
   */
   //label: PropTypes.string.isRequired,

   /**
   * The value displayed in the input
   */
   value: PropTypes.string,

   /**
   * Dash-assigned callback that should be called whenever any of the
   * properties change
   */
   setProps: PropTypes.func
 };

我正在使用此组件用法.py在

在用法.py-在

^{pr2}$

我的问题是当我将作为纯文本传递时,它工作得很好。但当我将值作为html标记传递时(即value=<h2>This is a text area</h1>),它给出了无效的语法错误。 如何将值作为html标记传递?在

谢谢。 当做。在


Tags: from文本importdividtargetstringvalue

热门问题