score:1
@juliomalves comment above was the answer. Thank you. I was looking in all the wrong places.
Here is the updated code, split into a page and a dynamically loaded component (with some new content for visibility).
import dynamic from 'next/dynamic'
import styled from "styled-components"
const Scene = dynamic(
() => import('./scene'),
{ ssr: false }
)
export default function App() {
return (
<div>
<ModelDiv>
<Scene/>
</ModelDiv>
</div>
)
}
const ModelDiv = styled.div`
display: block;
background-color: lightblue;
width: 100%;
height: 100vh;
`;
The corresponding component in scene.js:
import { Canvas } from '@react-three/fiber'
import { OrbitControls } from '@react-three/drei'
export default function Scene() {
return (
<Canvas>
<ambientLight intensity={1} />
<directionalLight position={[0, 1, 5]} intensity={1} />
<OrbitControls />
<mesh>
<boxGeometry args={[1, 1, 1]} />
<meshStandardMaterial color="yellow" />
</mesh>
</Canvas>
)
}
score:0
By running useLayoutEffect
on the server you can potentially send different html
content than the one that the app will produce when running on the client for the first time, hence the warning.
One way to fix this is not to render the component that uses useLayoutEffect
on the server.
You can do this by checking if the window
object is defined. When it is defined it means that your code is running on the client, and only then you should render your canvas
component.
Source: stackoverflow.com
Related Query
- Why am I getting this useLayoutEffect warning (not in a test)
- Why I am getting this warning message, does not conform to the required format, "yyyy-MM-dd" in ReactJS?
- Why I am getting this error - Error: EPERM: operation not permitted, mkdir 'C:\Users\Aniket' command not found: create-react-app
- Why is this code giving a warning about functions not being valid as a React child?
- Why does the jest mock function not getting executed in my test with react testing library?
- Why this SVG image from sprite-sheet is not getting rendered in HTML but not in React?
- Getting this warning "Functions are not valid as a React child"
- Why am I getting a warning of not having a unique key?
- TypeError: undefined is not an object (evaluating 'availableMeals.filter'). I don't why I am getting this error
- Why Am I getting this "document is not defined" error?
- Why am I getting this error? TypeError: this.state.items.sort is not a function
- Why i am not getting dropdown in react js can any one solve me this
- Why am I getting a 'no-unused-vars' warning in a for...of loop and how do I fix it?
- Why am I getting Warning: Functions are not valid as a React child?
- Why am I getting "potentially invalid reference access to a class field via this in a nested function" error
- redux-observable Promise is not getting resolved in unit test
- Why I am getting this error message when I run react js project first time in my system?
- Why is this returning the error .contains() is not a function
- Why am I getting "useContext is not a function" or "context is not defined"?
- Why I am getting 'Map' is not exported from 'react-leaflet'?
- Why am I getting "undefined is not an object (evaluating PropTypes.shape)"?
- Why am I getting ReferenceError: self is not defined when I import a client-side library?
- Why is clearTimeout not clearing the timeout in this react component?
- Why is this not scoped in React form onSubmit function?
- Why am I getting this error - 'You are calling withTheme(Component) with an undefined component.' -React JS
- Why am I getting the error message "Property 'then' does not exist on type 'AsyncThunkAction'"?
- Why am I getting this error (Tailwind + Next.js)? HookwebpackError, CssSyntaxError
- React - Why is binding this not required in this example?
- Why is this basic react-beautiful-dnd example not animating
- Getting OVERRIDING ACCESS_TOKEN warning on facebook logout button. This started a week ago
More Query from same tag
- Compile a JSX string to a component on the fly
- Apply style conditionally on a React component with json-style definitions
- Material UI - gutterBottom vs paragraph, difference?
- Rendering columns of buttons within div
- Using Google Web Fonts With Gatsby and Styled-Components
- Material Table: How to get the row data on Button click? (Not on row selection)
- How to make rating stars in react js?
- Sending message from register service worker to client page
- Handling errors in useEffect when fetching data from an API
- Auto-scroll in a nested list in ReactJs
- ComponentDidUpdate SetState ReactJS Infinite loop
- Clear checkbox in reactjs hooks after submitting
- I need to render a JSX element in Material-ui DataGrid
- react 25+5 clock for freecodecamp test fail
- Styling React Bootstrap Component in Active State
- Architecture in a react native app using WebSockets
- No routes matched location "/cart/2?qty=%201" react router dom v6
- How to properly erase an element from a React state array?
- Is there a way to make the parent Link exclude some child elements?
- Mapping data object with a type field to specific React Components with TypeScript
- React/Redux - Rest operator not working as expected
- Using custom functions in react
- React load fonts dynamically from the backend
- How to change the class of component after period of time?
- show reactjs icons dynamically icon names picking from JSON file
- Update className attribute
- What is the Proptype for HTMLDocument
- Migrate a API request from using promises to observable (using axios)
- React Module Parse Failed – react-map-gl
- How to send request to remote URLs?