Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/420.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想在react中运行纯javascript代码_Javascript_Reactjs_Canvas - Fatal编程技术网

我想在react中运行纯javascript代码

我想在react中运行纯javascript代码,javascript,reactjs,canvas,Javascript,Reactjs,Canvas,我有一个录音应用程序,可以保存画布。我也有一个反应化合物,我用织物白板。我想将我的注册码集成到此组件中。我是新来的反应,所以我不知道怎么做。我想做的是在我的react组件中保存canvas元素 文件 开始 停止 可以使用onClick属性设置javaScript代码可以运行的函数 例如: import React from 'react'; class AppTester extends React.Component { constructor(props){ su

我有一个录音应用程序,可以保存画布。我也有一个反应化合物,我用织物白板。我想将我的注册码集成到此组件中。我是新来的反应,所以我不知道怎么做。我想做的是在我的react组件中保存canvas元素


文件
开始
停止

可以使用onClick属性设置javaScript代码可以运行的函数

例如:

import React from 'react';

class AppTester extends React.Component {
    constructor(props){
        super(props);
        this.show = this.show.bind(this);
    }

    show(){
      //your code...
    }

    render(){
        return(
            <div>
                <h1 onClick={this.show}>hello!</h1>
            </div>
        )
    }
}

export default AppTester;
从“React”导入React;
类AppTester扩展了React.Component{
建造师(道具){
超级(道具);
this.show=this.show.bind(this);
}
show(){
//你的代码。。。
}
render(){
返回(
你好
)
}
}
导出默认AppTester;

我不能完全理解。你是在告诉我把我所有的js代码都放在show函数中吗?我分享了代码Sanbox链接,你有机会从那里编辑它吗?我会尝试一下,但这是你的解决方案。检查:如果你能等一下,我明天就试试。注册是指登录系统吗?通过录制,save是指.toDataUrl()还是使用save()和restore()?看起来您正在尝试使用ref,ref可以在函数中访问,您可以通过在画布上放置ref来访问画布,并在此ref上调用所需的函数。
import React from 'react';

class AppTester extends React.Component {
    constructor(props){
        super(props);
        this.show = this.show.bind(this);
    }

    show(){
      //your code...
    }

    render(){
        return(
            <div>
                <h1 onClick={this.show}>hello!</h1>
            </div>
        )
    }
}

export default AppTester;