reactjs - heroku 不想玩我的 p5-react 应用程序
问题描述
我试图将 p5.js 与 react 一起使用,但我的问题是它可以在本地工作,但是当我推送到 heroku 时出现错误
未捕获的 TypeError:超级表达式必须为 null 或函数
这是草图的代码:
import React from "react";
import Sketch from "react-p5";
export default () => {
let x = 0;
let y = 0;
let spacing = 10;
const setup = (p5, canvasParentRef) => {
// use parent to render the canvas in this ref
// (without that p5 will render the canvas outside of your component)
p5.createCanvas(500, 500).parent(canvasParentRef);
p5.background(0);
};
const draw = (p5) => {
// NOTE: Do not use setState in the draw function or in functions that are executed
// in the draw function...
// please use normal variables or class properties for these purposes
p5.stroke(255);
if (Math.random() < 0.5) {
p5.line(x, y, x + spacing, y + spacing);
} else {
p5.line(x, y + spacing, x + spacing, y);
}
x = x + spacing;
if (x > p5.width) {
x = 0;
y = y + spacing;
}
};
return <Sketch className="C64Sketch" setup={setup} draw={draw} />;
};
和组件:
import React, { Component } from 'react';
//import { appendScript, removeScript } from './ModScripts';
import Navbar from './Navbar';
import C64PRINT from './sketches/10PRINT';
class C64_10p extends Component {
render() {
return (
<div className='c64 component_container'>
<Navbar />
<div className="my_spill c64">
this is the famous C64 one line program. this vertion takes more then one line though.
</div>
<div className="10_print sketch_container">
<C64PRINT />
<a href='https://shawkai91.github.io/p5js-fafs/10PRINT/' target='_blank'>
here is a link to it because heroku was not liking how i was doing it
</a>
<div className="sketch_container-discription"></div>
</div>
</div>
);
}
}
export default C64_10p;
和一个链接(如果需要):https ://shawkai-test-app.herokuapp.com/
解决方案
通过使用“react-p5-wrapper”而不是“react-p5”让它工作
推荐阅读
- postgresql - 使用 pd_dumpall 而不是 pg_dump 备份 postgres 时的自定义格式 (-Fc)
- spring-boot - 千分尺弹簧遗产在带有 ClassNotFound 问题的 springboot 1.4.7 中不起作用
- php - Laravel 直到页面加载后才看到用户已登录
- folium - 如何将folium地图库的地图类型更改为Satelite或Terrain等?
- python - 如何使用一个 POST 路由以不同的方法接受数组或对象?
- prestashop - Prestashop 1.7:当订单免费时使用哪个钩子(不付款)
- php - 需要拆分数字值php的帮助
- next.js - Tailwind CSS 在构建后未应用样式
- python - 试图用 tkinter 观察两个 IntVar 并选择最小的数字
- flutter - BuiltValueGenerator - 一个包含大量代码的类