Comments (2)
this is an example of passing the initializer function to set state from the react docts beta
import { useState } from 'react';
function createInitialTodos() {
const initialTodos = [];
for (let i = 0; i < 50; i++) {
initialTodos.push({
id: i,
text: 'Item ' + (i + 1)
});
}
return initialTodos;
}
export default function TodoList() {
const [todos, setTodos] = useState(createInitialTodos);
const [text, setText] = useState('');
return (
<>
<input
value={text}
onChange={e => setText(e.target.value)}
/>
<button onClick={() => {
setText('');
setTodos([{
id: todos.length,
text: text
}, ...todos]);
}}>Add</button>
<ul>
{todos.map(item => (
<li key={item.id}>
{item.text}
</li>
))}
</ul>
</>
);
}
I am not sure why createCards() function is not initializing properly
from react.
Hi @Dave-Patsy
Looks like your question more Next.js related rather than react. When the client props don't match server props after hydration - it's means that server pre-rendering took place. This is a part of optimisation that Next.js doing even for "client" components. So, basically "client" components is pre-rendered due to ssr. If you want completely "client" component. You should lazily import component with option ssr: false
.
import dynamic from 'next/dynamic'
const Memory = dynamic(() => import('./components/memory'), { ssr: false });
I've did it an the problem is gone
from react.
Related Issues (20)
- Bug: HOT 1
- .
- Bug: On mobile devices, clicking a checkbox in a list of checkboxes will sometimes toggle the wrong one.
- Bug: node cached in the InternalNode,it's cause a huage memory leak HOT 2
- Improvement: Add a log when react-dom is running on RSC instead of SSR HOT 1
- Bug: Popover API not supported HOT 3
- Bug: How to deal with HTML popover in react HOT 4
- Bug: A SAMPLE ISSUE TO PARTICIPATE IN DISCUSSION
- Bug: A SAMPLE ISSUE
- Bug: onClick doesn't work on any element inside disabled fieldset in Firefox HOT 3
- Bug: Hydration fails with statically rendered html when wrapping component in <Suspense> HOT 1
- Bug: Error Boundary not updating and not calling componentDidCatch despite catching error HOT 3
- Source code for for React 16.14.0? HOT 13
- Bug: Events in separate roots are not batched HOT 2
- Bug: Component suspended by `use` fails to react when suspension depends on external store HOT 1
- Bug: Curly Brace Symbol Doesn't Show (change open attribute value) HOT 1
- Bug: performance deteriorates when using ReactDOM.createRoot instead of ReactDom.render for virtual-table. HOT 2
- postMessage getting spammed from developer tools when turned off in non-react site HOT 5
- Bug: ReadableStream can be written to after close
- Bug: Constraining children to type has no effect HOT 5
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.