Comments (5)
Hey @jamesrweb,
thanks a lot for your answer. I am not using Next.js, but do use strict mode in react due to the default configuration of the vite@latest composition. By removing the strict mode tag I also get rid of the duplicate canvas.
from react.
This worked! Please add that workaround into the readme file to help others solving this common confusion :)
For me, I moved the ReactP5Wrapper
outside of StrictMode
wrapper like this:
// main.tsx
// ...
// Remove the `StrictMode` wrapper, leaving the `App` unwrapped.
ReactDOM.createRoot(document.getElementById("root")!).render(<App />);
// App.tsx
// ...
function App() {
return (
<>
{/* The p5wrapper component is free from `StrictMode` */}
<ReactP5Wrapper sketch={sketch} />
<React.StrictMode>
{/* While this area has strict mode enabled */}
<p>Hello, strict mode!</p>
</React.StrictMode>
</>
);
}
from react.
Is your react app using strict mode?
Are you using NextJS?
P5 binds to the element reference of the containing element, should that element ever change or the reference differ, a new canvas will be rendered. Reacts strict mode does this as part of its "double render test" strategy.
NextJS causes this since the element would be rendered once on the server and once on the client (in such a case you should be using the @P5-wrapper/next implementation instead to work around that specific use case.
from react.
from react.
This worked! Please add that workaround into the readme file to help others solving this common confusion :)
For me, I moved the
ReactP5Wrapper
outside ofStrictMode
wrapper like this:// main.tsx // ... // Remove the `StrictMode` wrapper, leaving the `App` unwrapped. ReactDOM.createRoot(document.getElementById("root")!).render(<App />);// App.tsx // ... function App() { return ( <> {/* The p5wrapper component is free from `StrictMode` */} <ReactP5Wrapper sketch={sketch} /> <React.StrictMode> {/* While this area has strict mode enabled */} <p>Hello, strict mode!</p> </React.StrictMode> </> ); }
@jordiyapz would you be willing to submit a PR?
from react.
Related Issues (20)
- ReactP5Wrapper has additional pixels in height HOT 3
- Could not find a declaration file but the code works HOT 10
- TypeError: p5.loadSound is not a function HOT 4
- P5-wrapper size HOT 5
- Stop rerender of p5 component when redux variables update HOT 3
- Latest commits not in the npm registry HOT 5
- Issue building with Vite 5 HOT 16
- npm ERR! Usage Error: This project is configured to use npm HOT 2
- windowResized() not firing HOT 4
- Error in nextjs HOT 7
- Change p5 dependency version to minimum 1.4.1 HOT 9
- Examples directory doesn't exist, link broken on README HOT 3
- Module parse failed: Identifier 'XX' has already been declared (7762:41) HOT 3
- Is this package supported in React Native? HOT 1
- How to access custom props using abstracted updateWithProps
- Custom updaters as props for use in abstracted methods
- Missing typings for `ReactP5WrapperGuard` in 5.0.0-rc.0 HOT 2
- npm package for version 4.4.1 is empty HOT 3
- It creates new canvas once state is changed HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react.