GithubHelp home page GithubHelp logo

Bug: creating the initial state about react HOT 2 OPEN

Dave-Patsy avatar Dave-Patsy commented on April 24, 2024
Bug: creating the initial state

from react.

Comments (2)

Dave-Patsy avatar Dave-Patsy commented on April 24, 2024

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.

Werter12 avatar Werter12 commented on April 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.