Comments (5)
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.
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.
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.
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.
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)
- Duplicate IDs when using multiple tabs instances HOT 4
- [listbox] required prop does not work properly
- [menu-button]: target="_blank" for MenuButton / MenuLink
- Bump react-remove-scroll in reach/dialog to v2.5.5 HOT 3
- MenuLink with NextJS's next/link HOT 7
- Yarn install error on dev branch: Workspace not found (@reach-internal/test@workspace:*) HOT 1
- Add Portal Provider to be able to configure `containerRef`
- MenuLists in portals cause page to scroll with React 18 HOT 7
- Not able to run yarn install after cloning the repo HOT 1
- required filed of ListboxInput does not work HOT 1
- [ComboxInput] Chinese composition not handled
- Reach Tabs flashes all tab panes when visit the page HOT 1
- Reach UI is not currently maintained HOT 3
- Combobox: Make it possible to set initial navigationValue
- Latest supported React version HOT 3
- [Dropdown] False positive `isSelected` when descendant cannot be found
- using useMenuButtonContext inside Dropdown still throws error HOT 1
- typo in controlled switch warning hook
- In nextjs 13 the combobox options are going behind the parent div HOT 3
- UncontrolledTabs export 'useId' (imported as 'useId') was not found
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 reach-ui.