简体   繁体   English

React Error(TypeError):无法添加属性上下文,对象不可扩展

[英]React Error (TypeError): Can't add property context, object is not extensible

I'm trying to use react-clipboard inside a react component to allow a user to easily copy-paste some text into clipboard but my code isn't working. 我正在尝试在react组件内使用react-clipboard,以允许用户轻松地将一些文本复制粘贴到剪贴板中,但是我的代码无法正常工作。 I wonder if I'm missing something obvious. 我想知道我是否缺少明显的东西。 Here is my code (pls ignore the boilerplate for closing the modal): 这是我的代码(请忽略用于关闭模式的样板):

'use strict';
    import React from 'react';
    import { Modal } from 'react-bootstrap';
    import Clipboard from "react-clipboard";

    class CopyText extends React.Component {
      render() {
        let text = JSON.stringify(this.props.value, null, "  ");

        return (
          <div>
            <p>Press Cmd + C to copy:</p>
            <pre>{text}</pre>
            <Clipboard value={text} />
          </div>
          );    
      }
    }

    class CopyLinkModal extends React.Component {
      constructor(props) {
        super(props)
        this.onClick = this.onClick.bind(this);
      }
      onClick() {
        this.props.onHide();
      }
      render() {
        return (
          <Modal show={this.props.show} message={this.props.message} onHide={this.onClick}>
            <Modal.Body>
              <div className="linkMessage">
                <CopyText value={this.props.message} />
              </div>
            </Modal.Body>
            <Modal.Footer>
              <button onClick={this.onClick}>Close</button>
            </Modal.Footer>
          </Modal>
        )
      }
    }

    export default CopyLinkModal;

For the most part I'm following instruction from https://www.npmjs.com/package/react-clipboard but I'm still getting the TypeError: TypeError: Can't add property context, object is not extensible Thanks for any help. 在大多数情况下,我正在按照https://www.npmjs.com/package/react-clipboard上的说明进行操作,但是我仍然遇到TypeError:TypeError:无法添加属性上下文,对象不可扩展感谢任何救命。

From react-clipboard package.json : react-clipboard package.json

"dependencies": {
    "react": "^0.12.2"
}

Therefore ES6 classes are not supported. 因此,不支持ES6类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的TypeError:无法添加属性12,对象不可扩展 - Uncaught TypeError: Can't add property 12, object is not extensible Node.js React:无法添加属性上下文,对象不可扩展 - Node.js React: Can't add property context, object is not extensible 无法添加属性_tracking,对象不可扩展 - Can't add property _tracking, object is not extensible React App-TypeError:无法添加属性setState,对象不可扩展 - React App - TypeError: Cannot add property setState, object is not extensible 无法在react中分配新属性,得到了“无法添加属性xxx,对象不可扩展” - Can not assign new property in react , got ` Can't add property xxx, object is not extensible` 未捕获的类型错误:无法定义属性“x”:对象不可扩展 - Uncaught TypeError: can't define property "x": Object is not extensible 类型错误:无法定义属性“当前”:Object 不可扩展 - TypeError: can't define property “current”: Object is not extensible TypeError:无法添加属性 0,object 不可扩展 - TypeError: Cannot add property 0, object is not extensible React:无法添加属性“X”,对象不可扩展 - React : cannot add property 'X', object is not extensible 材料表类型错误:无法添加属性表数据,对象不可扩展 - Material-table TypeError: Cannot add property tableData, object is not extensible
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM