Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Inconsistent behavior on conditional render on mobile

Chiusa
#740 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
javascript, react
Ambito
frontend

Direzione di ricerca

Start by reproducing the conditional state change around the Draggable component, comparing the original wrapper with the individually wrapped Baz 1 and Baz 2 examples. Determine whether the behavior comes from React conditional rendering or react-draggable, and document the conditions that reproduce the inconsistency; the issue names no repository files or tests.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

If I have a component that looks like this:

const Foo = () => {
  const [state, setState] = useState(null);
  const renderBar = () => {
    if (state) { return (<div>Baz 1</div>); }
    return (<div>Baz 2</div>);
  }
  return (
    <Draggable>
      {renderBar()}
    </Draggable>
  );
}

Then there is a chance that when either Baz 1 or Baz 2 gets rendered, it's not draggable. I suspect that this has to do with the state changing and Draggable only applying to whichever gets the initial render.

This observation comes from about 2 hours of debugging... for context, in my project, state is actually passed into the Foo component and can be set outside of Foo. Baz 2 is a table of a lot of components, whose slow rendering may or may not have contributed to this inconsistent behavior.

I resolved the inconsistency by individually wrapping Baz1 and Baz2 like this:

const Foo = (props) => {
  const [state, setState] = useState(null);
  const renderBar = () => {
    if (state) { return (
      <Draggable>
        <div>Baz 1</div>
      </Draggable>
    ); }
    return (
      <Draggable>
        <div>Baz 2</div>
      </Draggable>
    );
  }
  return renderBar();
}

Is this inconsistency specific to react-draggable or is it an expected behavior of react?

Lingua principale
JavaScript
Stelle
9.3k
Fork
1k
Merge medio
2g 16h
PR unite (30g)
5

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di react-grid-layout/react-draggable

Tutte le issue di react-grid-layout/react-draggable

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.