Giter VIP home page Giter VIP logo

Comments (5)

bogdansoare avatar bogdansoare commented on August 20, 2024

I see that hasn't been much activity in the RFC regarding isomorphic IDs reactjs/rfcs#32 .

The only decent solution that I've found is to do something like https://github.com/thearnica/react-uid#server-side-friendly-uid which uses the Context API to track used IDs.

@ryanflorence what do you think ?

from reach-ui.

ryanflorence avatar ryanflorence commented on August 20, 2024

I was planning something exactly like that. I'm gonna wait for hooks to ship though so it's not so arduous.

from reach-ui.

mfix22 avatar mfix22 commented on August 20, 2024

Would this work:

let genId = (prefix, count) => `${prefix}-${count}`;

let count = -1;
let getInitialMenuState = () => ({
  // ...
  buttonId: genId("button", count++)
});

?
Or is the issue this could clash with other user code.

If so i'll push the PR. Will be easy to migrate to hooks.

from reach-ui.

stereobooster avatar stereobooster commented on August 20, 2024

Accept a props.id before autogenerating one

export const useId = (defaultValue) => {
  const [id] = useState(defaultValue || genId);
  return id;
};

Generate ids in a deterministic way so that rehydrating a server render works (I think it ought to be broken right now)

I guess we need something like this https://github.com/thearnica/react-uid. It is actually pretty hard to solve it in user land, maybe we need to ask React team?

from reach-ui.

venikx avatar venikx commented on August 20, 2024

It seems to be that the react-uid library is now using hooks and the hooks are SSR friendly. So I suppose we could change the UUID generator to the react-uid one?

Source: https://github.com/thearnica/react-uid#hooks-167

from reach-ui.

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.