GithubHelp home page GithubHelp logo

Comments (7)

andymantell avatar andymantell commented on June 26, 2024

Thanks @stachow - I will take a look at this soon. Are you managing ok for a second if I don't get to this for a few days?

from govuk-react-jsx.

andymantell avatar andymantell commented on June 26, 2024

Interesting, this doesn't seem to happen for me. Would you be able to put together a minimal reproduction if it's not too much trouble? No worries if not, but it might speed up a fix if you are able to.

from govuk-react-jsx.

andymantell avatar andymantell commented on June 26, 2024

are you doing something like initialising this component without any items, but then loading in the items later e.g. as the result of an async call? So you get that first empty render happening without any checkboxes present?

from govuk-react-jsx.

stachow avatar stachow commented on June 26, 2024

Cheers for the response. This one is very edge-casey. Due to a bug in my code, the radios are put in to the DOM on page load, then instantly removed (thereby upsetting the internal JS leading to the console error). A repro is below. This is no longer an issue for me as the fix in my code prevents this initial "micro" rendering of the radios.

import { Radios } from "govuk-react-jsx";
import { useEffect, useState } from "react";

function App() {
  const [status, setStatus] = useState("idle");

  useEffect(() => {
    if (status === "idle") {
      // For error to appear in console, this delay must be tiny. If >=20ms on my machine, 
      //  then no error.
      setTimeout(() => setStatus("loading"), 5);
    }
    if (status === "loading") {
      setTimeout(() => setStatus("loaded"), 300);
    }
  }, [status]);

  return (
    <div className="App">
      {
        /* 
        Bug in my code on the following line: 
        - lifecycle of status is "idle" -> "loading" -> "loaded"
        - following check should be status === "loaded" to prevent radios being rendered 
           when status === "idle", then whipped out of DOM when "loading" (leading to console error)  
           then reinserted when "loaded"
        */
        status !== "loading" && (
          <Radios
            name="r"
            items={[{ reactListKey: "1", value: "1", children: "foo" }]}
            onChange={() => {}}
          ></Radios>
        )
      }
    </div>
  );
}

export default App;

from govuk-react-jsx.

stachow avatar stachow commented on June 26, 2024

BTW - as you may have guessed we are investigating using your library (nice work!), if you search for me on the gov digital slack you'll see which department. Cheers

from govuk-react-jsx.

andymantell avatar andymantell commented on June 26, 2024

ah thanks for explaining the scenario @stachow. Glad that you've fixed around it for now, but I agree, it would be nice if these components were able to handle such a situation. Should be an easy enough fix - I'll try and get it into the next release when I do the [email protected] upgrade.

from govuk-react-jsx.

andymantell avatar andymantell commented on June 26, 2024

Hi @stachow. This is now fixed in [email protected]

from govuk-react-jsx.

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.