[英]Property 'modules' does not exist on type 'typeof MyEditor'.ts(2339)
Trying to add a rich text editor and am running across the error in the title. 尝试添加富文本格式编辑器,并在标题中遇到错误。 Basically I need to know how in TypeScript to declare what properties my class component has.
基本上,我需要知道如何在TypeScript中声明类组件具有的属性。 This is a react project.
这是一个反应项目。 Anyone have any ideas?
有人有想法么? Here is the code.
这是代码。 The part i'm running into is when it comes to the .modules.
我遇到的部分是关于.modules的。
import React from 'react';
import ReactQuill from 'react-quill'; // ES6
type modules = {
}
class MyEditor<modules> extends React.Component<any, any, {}> {
constructor(props) {
super(props)
this.state = { text: this.props.text } // You can also pass a Quill Delta here
this.handleChange = this.handleChange.bind(this)
}
shouldComponentUpdate(nextProps) { // error here
if (nextProps.className) {
return false
}
}
handleChange(value) {
this.setState({ text: value })
this.props.gatherBody(value)
}
render() {
return (
<ReactQuill value={this.state.text}
onChange={this.handleChange}
modules={MyEditor.modules}
/>
)
}
}
MyEditor.modules = {
toolbar: [
[{ 'header': '1' }, { 'header': '2' }, { 'font': [] }],
[{ size: [] }],
['bold', 'italic', 'underline', 'strike', 'blockquote'],
[{ 'list': 'ordered' }, { 'list': 'bullet' },
{ 'indent': '-1' }, { 'indent': '+1' }],
['clean']
],
clipboard: {
// toggle to add extra line breaks when pasting HTML:
matchVisual: false,
}
}
export default MyEditor
You have to declare a static property inside the component. 您必须在组件内部声明一个静态属性。 Code below.
下面的代码。
import React, { Component } from 'react';
import ReactQuill from 'react-quill'; // ES6
class MyEditor extends React.Component<any, any, {}> {
constructor(props) {
super(props)
this.state = { text: this.props.text } // You can also pass a Quill Delta here
this.handleChange = this.handleChange.bind(this)
}
static modules: {} = {
modules: {}
}
shouldComponentUpdate(nextProps) { // error here
if (nextProps.className) {
return false
}
}
handleChange(value) {
this.setState({ text: value })
this.props.gatherBody(value)
}
render() {
return (
<ReactQuill value={this.state.text}
onChange={this.handleChange}
modules={MyEditor.modules}
/>
)
}
}
MyEditor.modules = {
toolbar: [
[{ 'header': '1' }, { 'header': '2' }, { 'font': [] }],
[{ size: [] }],
['bold', 'italic', 'underline', 'strike', 'blockquote'],
[{ 'list': 'ordered' }, { 'list': 'bullet' },
{ 'indent': '-1' }, { 'indent': '+1' }],
['clean']
],
clipboard: {
// toggle to add extra line breaks when pasting HTML:
matchVisual: false,
}
}
export default MyEditor
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.